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.
-
#verbose_name ⇒ Object
readonly
Returns the value of attribute verbose_name.
-
#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.
-
#cp(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.
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 |
# File 'lib/branch.rb', line 130 def initialize(repo, version, travis, branch_suff) GitMaintain::checkDirectConstructor(self.class) @repo = repo @travis = travis @version = version @branch_suff = branch_suff if version =~ /^[0-9]+$/ @local_branch = "dev/stable-v#{@version}/#{@branch_suff}" @remote_branch ="stable-v#{@version}" @branch_type = :std @verbose_name = "v"+version else @remote_branch = @local_branch = version @branch_type = :user_specified @verbose_name = version end @head = @repo.runGit("rev-parse #{@local_branch}") @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.
155 156 157 |
# File 'lib/branch.rb', line 155 def head @head end |
#local_branch ⇒ Object (readonly)
Returns the value of attribute local_branch.
155 156 157 |
# File 'lib/branch.rb', line 155 def local_branch @local_branch end |
#remote_branch ⇒ Object (readonly)
Returns the value of attribute remote_branch.
155 156 157 |
# File 'lib/branch.rb', line 155 def remote_branch @remote_branch end |
#remote_ref ⇒ Object (readonly)
Returns the value of attribute remote_ref.
155 156 157 |
# File 'lib/branch.rb', line 155 def remote_ref @remote_ref end |
#stable_head ⇒ Object (readonly)
Returns the value of attribute stable_head.
155 156 157 |
# File 'lib/branch.rb', line 155 def stable_head @stable_head end |
#verbose_name ⇒ Object (readonly)
Returns the value of attribute verbose_name.
155 156 157 |
# File 'lib/branch.rb', line 155 def verbose_name @verbose_name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
155 156 157 |
# File 'lib/branch.rb', line 155 def version @version end |
Class Method Details
.check_opts(opts) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/branch.rb', line 84 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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/branch.rb', line 93 def self.execAction(opts, action) repo = Repo::load() travis = TravisChecker::load(repo) if NO_FETCH_ACTIONS.index(action) == nil then repo.stableUpdate() end branchList=[] if opts[:manual_branch] == nil then branchList = repo.getStableList(opts[:br_suff]).map(){|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 branch }.compact() else branchList = [ Branch::load(repo, opts[:manual_branch], travis, opts[:br_suff]) ] end branchList.each(){|branch| puts "###############################" puts "# Working on #{branch.verbose_name}" 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 74 75 76 77 78 79 80 81 82 |
# 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} if action != :merge optsParser.on("-B", "--manual-branch <branch name>", "Work on a specific (non-stable) branch.") { |val| opts[:manual_branch] = val} end 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] = true} when :steal optsParser. += "[-a]" optsParser.on("-a", "--all", "Check all commits from master. "+ "By default only new commits (since last successful run) are considered.") { |val| opts[:all] = true} end end |
Instance Method Details
#checkout ⇒ Object
Checkout the repo to the given branch
169 170 171 172 173 174 |
# File 'lib/branch.rb', line 169 def checkout() print @repo.runGit("checkout -q #{@local_branch}") if $? != 0 then raise "Error: Failed to checkout the branch" end end |
#cp(opts) ⇒ Object
Cherry pick an array of commits
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/branch.rb', line 177 def cp(opts) opts[:commits].each(){|commit| @repo.runGit("cherry-pick #{commit}") if $? != 0 then puts "Cherry pick failure. Starting bash for manual fixes. Exit shell to continue" @repo.runSystem("bash") puts "Continuing..." end make_pretty(commit) } end |
#is_targetted?(opts) ⇒ Boolean
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/branch.rb', line 157 def is_targetted?(opts) return true if @branch_type == :user_specified 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
218 219 220 |
# File 'lib/branch.rb', line 218 def list(opts) GitMaintain::checkLog(opts, @local_branch, @remote_ref, nil) end |
#merge(opts) ⇒ Object
Merge merge_branch into this one
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/branch.rb', line 223 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
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/branch.rb', line 245 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
284 285 286 |
# File 'lib/branch.rb', line 284 def monitor_stable(opts) puts "Status for v#{@version}: " + @travis.getStableState(@stable_head) end |
#push(opts) ⇒ Object
Push the branch to the validation repo
240 241 242 |
# File 'lib/branch.rb', line 240 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
268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/branch.rb', line 268 def push_stable(opts) if (opts[:no_travis] != true && @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
299 300 301 |
# File 'lib/branch.rb', line 299 def release(opts) puts "#No release command available for this repo" end |
#reset(opts) ⇒ Object
Reset the branch to the upstream stable one
289 290 291 292 293 294 295 296 297 |
# File 'lib/branch.rb', line 289 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
190 191 192 193 194 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 190 def steal(opts) base_ref=@stable_base # If we are not force checking everything, # try to start from the last tag we steal upto if opts[:all] != true then sha = @repo.runGit("rev-parse 'git-maintain/steal/last/#{@stable_base}' 2>&1") if $? == 0 then base_ref=sha puts "# INFO: Starting from last successfull run:" puts "# INFO: " + @repo.runGit("show --format=oneline #{base_ref}") end end master_sha=@repo.runGit("rev-parse origin/master") res = steal_all(opts, "#{base_ref}..#{master_sha}") # If we picked all the commits (or nothing happened) # Mark the current master as the last checked point so we # can just steal from this point on the next run if res == true then @repo.runGit("tag -f 'git-maintain/steal/last/#{@stable_base}' origin/master") puts "# INFO: Marking new last successfull run at:" puts "# INFO: " + @repo.runGit("show --format=oneline #{master_sha}") end end |