Class: GitMaintain::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/repo.rb

Constant Summary collapse

ACTION_LIST =
[
    :list_branches,
    # Internal commands for completion
    :list_suffixes, :submit_release
]
ACTION_HELP =
[
    "* submit_release: Push the to stable and create the release packages",
]
@@VALID_REPO =
"github"
@@STABLE_REPO =
"stable"
@@SUBMIT_BINARY =
"git-release"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Repo

Returns a new instance of Repo.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/repo.rb', line 39

def initialize(path=nil)
    GitMaintain::checkDirectConstructor(self.class)

    @path = path
    @stable_list=nil
    @stable_branches=nil
    @suffix_list=nil

    if path == nil
        @path = Dir.pwd()
    end

    @valid_repo = runGit("config maintain.valid-repo 2> /dev/null").chomp()
    @valid_repo = @@VALID_REPO if @valid_repo == ""
    @stable_repo = runGit("config maintain.stable-repo 2>/dev/null").chomp()
    @stable_repo = @@STABLE_REPO if @stable_repo == ""

    @remote_valid=runGit("remote -v | egrep '^#{@valid_repo}' | grep fetch |
                        awk '{ print $2}' | sed -e 's/.*://' -e 's/\\.git//'")
    @remote_stable=runGit("remote -v | egrep '^#{@stable_repo}' | grep fetch |
                              awk '{ print $2}' | sed -e 's/.*://' -e 's/\\.git//'")
    @stable_base_patterns=
        runGit("config --get-regexp   stable-base | egrep '^stable-base\.' | "+
               "sed -e 's/stable-base\.//' -e 's/---/\\//g'").split("\n").inject({}){ |m, x|
        y=x.split(" ");
        m[y[0]] = y[1]
        m
        }
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



68
69
70
# File 'lib/repo.rb', line 68

def path
  @path
end

#remote_stableObject (readonly)

Returns the value of attribute remote_stable.



68
69
70
# File 'lib/repo.rb', line 68

def remote_stable
  @remote_stable
end

#remote_validObject (readonly)

Returns the value of attribute remote_valid.



68
69
70
# File 'lib/repo.rb', line 68

def remote_valid
  @remote_valid
end

#stable_repoObject (readonly)

Returns the value of attribute stable_repo.



68
69
70
# File 'lib/repo.rb', line 68

def stable_repo
  @stable_repo
end

#valid_repoObject (readonly)

Returns the value of attribute valid_repo.



68
69
70
# File 'lib/repo.rb', line 68

def valid_repo
  @valid_repo
end

Class Method Details

.check_opts(opts) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/repo.rb', line 22

def self.check_opts(opts)
    if opts[:action] == :submit_release then
        if opts[:br_suff] != "master" then
            raise "Action #{opts[:action]} can only be done on 'master' suffixed branches"
        end
    end
end

.execAction(opts, action) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/repo.rb', line 30

def self.execAction(opts, action)
    repo   = Repo::load()

    if action == :submit_release then
        repo.stableUpdate()
    end
    repo.send(action, opts)
end

.load(path = ".") ⇒ Object



16
17
18
19
20
# File 'lib/repo.rb', line 16

def self.load(path=".")
    dir = Dir.pwd()
    repo_name = File.basename(dir)
    return GitMaintain::loadClass(Repo, repo_name, dir)
end

Instance Method Details

#findStableBase(branch) ⇒ Object



173
174
175
176
177
178
# File 'lib/repo.rb', line 173

def findStableBase(branch)
    @stable_base_patterns.each(){|pattern, base|
        return base if branch =~ /#{pattern}\// || branch =~ /#{pattern}$/
    }
    raise("Could not a find a stable base for branch #{branch}")
end

#getStableList(br_suff) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/repo.rb', line 97

def getStableList(br_suff)
    return @stable_list if @stable_list != nil

    @stable_list=runGit("branch").split("\n").map(){|x|
        x=~ /dev\/stable-v[0-9]+\/#{br_suff}/ ?
            x.gsub(/\*?\s*dev\/stable-v([0-9]+)\/#{br_suff}\s*$/, '\1') :
            nil}.compact().uniq()

    return @stable_list
end

#getSuffixListObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/repo.rb', line 108

def getSuffixList()
    return @suffix_list if @suffix_list != nil

    @suffix_list = runGit("branch").split("\n").map(){|x|
        x=~ /dev\/stable-v[0-9]+\/[a-zA-Z0-9_-]+/ ?
            x.gsub(/\*?\s*dev\/stable-v[0-9]+\/([a-zA-Z0-9_-]+)\s*$/, '\1') :
            nil}.compact().uniq()

    return @suffix_list
end

#list_branches(opts) ⇒ Object



180
181
182
# File 'lib/repo.rb', line 180

def list_branches(opts)
    puts getStableList(opts[:br_suff])
end

#list_suffixes(opts) ⇒ Object



183
184
185
# File 'lib/repo.rb', line 183

def list_suffixes(opts)
    puts getSuffixList()
end

#run(cmd) ⇒ Object



70
71
72
# File 'lib/repo.rb', line 70

def run(cmd)
    return `cd #{@path} && #{cmd}`
end

#runGit(cmd) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/repo.rb', line 76

def runGit(cmd)
    if ENV["DEBUG"].to_s() != "" then
        puts "Called from #{caller[1]}"
        puts "Running git command '#{cmd}'"
    end
    return `git --work-tree=#{@path} #{cmd}`.chomp()
end

#runGitImap(cmd) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/repo.rb', line 83

def runGitImap(cmd)
    return `export GIT_ASKPASS=$(dirname $(dirname $(which git)))/lib/git-core/git-gui--askpass;
          if [ ! -f $GIT_ASKPASS ]; then
          	export GIT_ASKPASS=$(dirname $(which git))/git-gui--askpass;
          fi;
          if [ ! -f $GIT_ASKPASS ]; then
          	export GIT_ASKPASS=/usr/lib/ssh/ssh-askpass;
          fi; git --work-tree=#{@path} imap-send #{cmd}`
end

#runSystem(cmd) ⇒ Object



73
74
75
# File 'lib/repo.rb', line 73

def runSystem(cmd)
    return system("cd #{@path} && #{cmd}")
end

#stableUpdateObject



93
94
95
96
# File 'lib/repo.rb', line 93

def stableUpdate()
    puts "# Fetching stable updates..."
    runGit("fetch #{@stable_repo}")
end

#submit_release(opts) ⇒ Object



186
187
188
# File 'lib/repo.rb', line 186

def submit_release(opts)
    submitReleases(opts)
end

#submitReleases(opts) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/repo.rb', line 119

def submitReleases(opts)
    remote_tags=runGit("ls-remote --tags #{@stable_repo} |
                         egrep 'refs/tags/v[0-9.]*$'").split("\n").map(){
        |x| x.gsub(/.*refs\/tags\//, '')
    }
    local_tags =runGit("tag -l | egrep '^v[0-9.]*$'").split("\n")

    new_tags = local_tags - remote_tags
    if new_tags.empty? then
        puts "All tags are already submitted."
        return
    end

    puts "This will officially release these tags: #{new_tags.join(", ")}"
    rep = GitMaintain::confirm(opts, "release them")
    if rep != 'y' then
        raise "Aborting.."
    end

    if @NOTIFY_RELEASE != false
        mail_path=`mktemp`.chomp()
        mail = File.open(mail_path, "w+")
        mail.puts "From " + runGit("rev-parse HEAD") + " " + `date`.chomp()
        mail.puts "From: " + runGit("config user.name") +
                  " <" + runGit("config user.email") +">"
        mail.puts "To: " + runGit("config patch.target")
        mail.puts "Date: " + `date -R`.chomp()
        mail.puts "Subject: [ANNOUNCE] " + File.basename(@path) + " " +
                  (new_tags.length > 1 ?
                       (new_tags[0 .. -2].join(", ") + " and " + new_tags[-1]) :
                       new_tags.join(" ")) +
                  " has been tagged/released"
        mail.puts ""
        mail.puts "Here's the information from the tags:"
        new_tags.sort().each(){|tag|
            mail.puts `git show #{tag} --no-decorate -q | awk '!p;/^-----END PGP SIGNATURE-----/{p=1}'`
            mail.puts ""
        }
        mail.puts "It's available at the normal places:"
        mail.puts ""
        mail.puts "git://github.com/#{@remote_stable}"
        mail.puts "https://github.com/#{@remote_stable}/releases"
        mail.close()

        puts runGitImap("< #{mail_path}; rm -f #{mail_path}")
    end

    puts "Last chance to cancel before submitting"
    rep= GitMaintain::confirm(opts, "submit these releases")
    if rep != 'y' then
        raise "Aborting.."
    end
    puts `#{@@SUBMIT_BINARY}`
end