Class: GitMaintain::Repo

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

Constant Summary collapse

VALID_REPO =
"github"
STABLE_REPO =
"stable"
SUBMIT_BINARY =
"git-release"
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",
]

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
# 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
    @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.



62
63
64
# File 'lib/repo.rb', line 62

def path
  @path
end

#remote_stableObject (readonly)

Returns the value of attribute remote_stable.



62
63
64
# File 'lib/repo.rb', line 62

def remote_stable
  @remote_stable
end

#remote_validObject (readonly)

Returns the value of attribute remote_valid.



62
63
64
# File 'lib/repo.rb', line 62

def remote_valid
  @remote_valid
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



165
166
167
168
169
170
# File 'lib/repo.rb', line 165

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

#getStableList(br_suff) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/repo.rb', line 91

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



102
103
104
105
106
107
108
109
110
111
# File 'lib/repo.rb', line 102

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



172
173
174
# File 'lib/repo.rb', line 172

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

#list_suffixes(opts) ⇒ Object



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

def list_suffixes(opts)
    puts getSuffixList()
end

#run(cmd) ⇒ Object



64
65
66
# File 'lib/repo.rb', line 64

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

#runGit(cmd) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/repo.rb', line 70

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



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

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



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

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

#stableUpdateObject



87
88
89
90
# File 'lib/repo.rb', line 87

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

#submit_release(opts) ⇒ Object



178
179
180
# File 'lib/repo.rb', line 178

def submit_release(opts)
    submitReleases()
end

#submitReleasesObject



113
114
115
116
117
118
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
# File 'lib/repo.rb', line 113

def submitReleases()
    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("release them")
    if rep != 'y' then
        raise "Aborting.."
    end

    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}")

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