Class: GitMaintain::Branch
- Inherits:
-
Object
- Object
- GitMaintain::Branch
- Defined in:
- lib/branch.rb
Direct Known Subclasses
Constant Summary collapse
- ACTION_LIST =
[ :cp, :steal, :list, :merge, :push, :monitor, :push_stable, :monitor_stable, :release, :reset ]
- NO_FETCH_ACTIONS =
[ :cp, :merge, :monitor, :release ]
- NO_CHECKOUT_ACTIONS =
[ :list, :push, :monitor, :monitor_stable ]
- ACTION_HELP =
[ "* cp: Backport commits and eventually push them to github", "* steal: Steal commit from upstream that fixes commit in the branch or were tagged as stable", "* list: List commit present in the branch but not in the stable branch", "* merge: Merge branch with suffix specified in -m <suff> into the main branch", "* push: Push branches to github for validation", "* monitor: Check the travis state of all branches", "* push_stable: Push to stable repo", "* monitor_stable: Check the travis state of all stable branches", "* release: Create new release on all concerned branches", "* reset: Reset branch against upstream", ]
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#local_branch ⇒ Object
readonly
Returns the value of attribute local_branch.
-
#remote_branch ⇒ Object
readonly
Returns the value of attribute remote_branch.
-
#remote_ref ⇒ Object
readonly
Returns the value of attribute remote_ref.
-
#stable_head ⇒ Object
readonly
Returns the value of attribute stable_head.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .check_opts(opts) ⇒ Object
- .execAction(opts, action) ⇒ Object
- .load(repo, version, travis, branch_suff) ⇒ Object
- .set_opts(action, optsParser, opts) ⇒ Object
Instance Method Summary collapse
-
#checkout ⇒ Object
Checkout the repo to the given branch.
-
#cherry_pick(opts) ⇒ Object
Cherry pick an array of commits.
-
#initialize(repo, version, travis, branch_suff) ⇒ Branch
constructor
A new instance of Branch.
- #is_targetted?(opts) ⇒ Boolean
-
#list(opts) ⇒ Object
List commits in the branch that are no in the stable branch.
-
#merge(opts) ⇒ Object
Merge merge_branch into this one.
-
#monitor(opts) ⇒ Object
Monitor the build status on Travis.
-
#monitor_stable(opts) ⇒ Object
Monitor the build status of the stable branch on Travis.
-
#push(opts) ⇒ Object
Push the branch to the validation repo.
-
#push_stable(opts) ⇒ Object
Push branch to the stable repo.
- #release(opts) ⇒ Object
-
#reset(opts) ⇒ Object
Reset the branch to the upstream stable one.
-
#steal(opts) ⇒ Object
Steal upstream commits that are not in the branch.
Constructor Details
#initialize(repo, version, travis, branch_suff) ⇒ Branch
Returns a new instance of Branch.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/branch.rb', line 114 def initialize(repo, version, travis, branch_suff) GitMaintain::checkDirectConstructor(self.class) @repo = repo @version = version @travis = travis @branch_suff = branch_suff @local_branch = "dev/stable-v#{@version}/#{@branch_suff}" @head = @repo.runGit("rev-parse #{@local_branch}") @remote_branch ="stable-v#{@version}" @remote_ref = "#{Repo::STABLE_REPO}/#{@remote_branch}" @stable_head = @repo.runGit("rev-parse #{@remote_ref}") @stable_base = @repo.findStableBase(@local_branch) end |
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
130 131 132 |
# File 'lib/branch.rb', line 130 def head @head end |
#local_branch ⇒ Object (readonly)
Returns the value of attribute local_branch.
130 131 132 |
# File 'lib/branch.rb', line 130 def local_branch @local_branch end |
#remote_branch ⇒ Object (readonly)
Returns the value of attribute remote_branch.
130 131 132 |
# File 'lib/branch.rb', line 130 def remote_branch @remote_branch end |
#remote_ref ⇒ Object (readonly)
Returns the value of attribute remote_ref.
130 131 132 |
# File 'lib/branch.rb', line 130 def remote_ref @remote_ref end |
#stable_head ⇒ Object (readonly)
Returns the value of attribute stable_head.
130 131 132 |
# File 'lib/branch.rb', line 130 def stable_head @stable_head end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
130 131 132 |
# File 'lib/branch.rb', line 130 def version @version end |
Class Method Details
.check_opts(opts) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/branch.rb', line 75 def self.check_opts(opts) if opts[:action] == :push_stable || opts[:action] == :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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/branch.rb', line 84 def self.execAction(opts, action) repo = Repo::load() travis = TravisChecker::load(repo) if NO_FETCH_ACTIONS.index(action) == nil then repo.stableUpdate() end repo.getStableList(opts[:br_suff]).each(){|br| branch = Branch::load(repo, br, travis, opts[:br_suff]) case branch.is_targetted?(opts) when :too_old puts "# Skipping older v#{branch.version}" next when :no_match puts "# Skipping v#{branch.version} not matching #{opts[:version].to_s()}" next end puts "###############################" puts "# Working on v#{branch.version}" puts "###############################" if NO_CHECKOUT_ACTIONS.index(action) == nil then branch.checkout() end branch.send(action, opts) } end |
.load(repo, version, travis, branch_suff) ⇒ Object
37 38 39 40 |
# File 'lib/branch.rb', line 37 def self.load(repo, version, travis, branch_suff) repo_name = File.basename(repo.path) return GitMaintain::loadClass(Branch, repo_name, repo, version, travis, branch_suff) end |
.set_opts(action, optsParser, opts) ⇒ Object
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 68 69 70 71 72 73 |
# File 'lib/branch.rb', line 42 def self.set_opts(action, optsParser, opts) opts[:base_ver] = 0 opts[:version] = /.*/ opts[:commits] = [] opts[:do_merge] = false opts[:push_force] = false opts[:no_travis] = false optsParser.on("-v", "--base-version [MIN_VER]", Integer, "Older release to consider.") { |val| opts[:base_ver] = val} optsParser.on("-V", "--version [regexp]", Regexp, "Regexp to filter versions.") { |val| opts[:version] = val} case action when :cp optsParser. += "-c <sha1> [-c <sha1> ...]" optsParser.on("-c", "--sha1 [SHA1]", String, "Commit to cherry-pick. Can be used multiple time.") { |val| opts[:commits] << val} when :merge optsParser. += "-m <suffix>" optsParser.on("-m", "--merge [SUFFIX]", "Merge branch with suffix.") { |val| opts[:do_merge] = val} when :push optsParser. += "[-f]" optsParser.on("-f", "--force", "Add --force to git push (for 'push' action).") { |val| opts[:push_force] = val} when :push_stable optsParser. += "[-T]" optsParser.on("-T", "--no-travis", "Ignore Travis build status and push anyway.") { |val| opts[:no_travis] = val} end end |
Instance Method Details
#checkout ⇒ Object
Checkout the repo to the given branch
143 144 145 146 147 148 |
# File 'lib/branch.rb', line 143 def checkout() print @repo.runGit("checkout -q #{@local_branch}") if $? != 0 then raise "Error: Failed to checkout the branch" end end |
#cherry_pick(opts) ⇒ Object
Cherry pick an array of commits
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/branch.rb', line 151 def cherry_pick(opts) if opts[:commits].length > 0 then @repo.runGit("cherry-pick #{opts[:commits].join(" ")}") if $? != 0 then puts "Cherry pick failure. Starting bash for manual fixes. Exit shell to continue" @repo.runSystem("bash") puts "Continuing..." end end end |
#is_targetted?(opts) ⇒ Boolean
132 133 134 135 136 137 138 139 140 |
# File 'lib/branch.rb', line 132 def is_targetted?(opts) if @version.to_i < opts[:base_ver] then return :too_old end if @version !~ opts[:version] then return :no_match end return true end |
#list(opts) ⇒ Object
List commits in the branch that are no in the stable branch
168 169 170 |
# File 'lib/branch.rb', line 168 def list(opts) GitMaintain::checkLog(opts, @local_branch, @remote_ref, nil) end |
#merge(opts) ⇒ Object
Merge merge_branch into this one
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/branch.rb', line 173 def merge(opts) merge_branch = "dev/stable-v#{@version}/#{opts[:do_merge]}" rep = GitMaintain::checkLog(opts, merge_branch, @local_branch, "merge") if rep == "y" then @repo.runGit("merge #{merge_branch}") if $? != 0 then puts "Merge failure. Starting bash for manual fixes. Exit shell to continue" @repo.runSystem("bash") puts "Continuing..." end else puts "Skipping merge" return end end |
#monitor(opts) ⇒ Object
Monitor the build status on Travis
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/branch.rb', line 195 def monitor(opts) st = @travis.getValidState(head) puts "Status for v#{@version}: " + st if st == "failed" rep = "y" suff="" while rep == "y" rep = GitMaintain::confirm(opts, "see the build log#{suff}") if rep == "y" then log = @travis.getValidLog(head) tmp = `mktemp`.chomp() tmpfile = File.open(tmp, "w+") tmpfile.puts(log) tmpfile.close() system("less -r #{tmp}") `rm -f #{tmp}` end suff=" again" end end end |
#monitor_stable(opts) ⇒ Object
Monitor the build status of the stable branch on Travis
234 235 236 |
# File 'lib/branch.rb', line 234 def monitor_stable(opts) puts "Status for v#{@version}: " + @travis.getStableState(@stable_head) end |
#push(opts) ⇒ Object
Push the branch to the validation repo
190 191 192 |
# File 'lib/branch.rb', line 190 def push(opts) @repo.runGit("push #{opts[:push_force] == true ? "-f" : ""} #{Repo::VALID_REPO} #{@local_branch}") end |
#push_stable(opts) ⇒ Object
Push branch to the stable repo
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/branch.rb', line 218 def push_stable(opts) if opts[:no_travis] != true && @travis.checkValidState(@head) != true then puts "Build is not passed on travis. Skipping push to stable" return end rep = GitMaintain::checkLog(opts, @local_branch, @remote_ref, "submit") if rep == "y" then @repo.runGit("push #{Repo::STABLE_REPO} #{@local_branch}:#{@remote_branch}") else puts "Skipping push to stable" return end end |
#release(opts) ⇒ Object
249 250 251 |
# File 'lib/branch.rb', line 249 def release(opts) puts "#No release command available for this repo" end |
#reset(opts) ⇒ Object
Reset the branch to the upstream stable one
239 240 241 242 243 244 245 246 247 |
# File 'lib/branch.rb', line 239 def reset(opts) rep = GitMaintain::checkLog(opts, @local_branch, @remote_ref, "reset") if rep == "y" then @repo.runGit("reset --hard #{@remote_ref}") else puts "Skipping reset" return end end |
#steal(opts) ⇒ Object
Steal upstream commits that are not in the branch
163 164 165 |
# File 'lib/branch.rb', line 163 def steal(opts) steal_all(opts, "#{@stable_base}..origin/master") end |