Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: cros_mark_as_stable.py

Issue 6250037: Make push and clean more robust. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Fix checkout Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """This module uprevs a given package's ebuild to the next revision.""" 7 """This module uprevs a given package's ebuild to the next revision."""
8 8
9 9
10 import fileinput 10 import fileinput
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 # ======================= End Global Helper Functions ======================== 221 # ======================= End Global Helper Functions ========================
222 222
223 223
224 def Clean(tracking_branch): 224 def Clean(tracking_branch):
225 """Cleans up uncommitted changes. 225 """Cleans up uncommitted changes.
226 226
227 Args: 227 Args:
228 tracking_branch: The tracking branch we want to return to after the call. 228 tracking_branch: The tracking branch we want to return to after the call.
229 """ 229 """
230 # Safety case in case we got into a bad state with a previous build.
231 try:
232 _SimpleRunCommand('git rebase --abort')
233 except:
234 pass
235
230 _SimpleRunCommand('git reset HEAD --hard') 236 _SimpleRunCommand('git reset HEAD --hard')
231 branch = GitBranch(STABLE_BRANCH_NAME, tracking_branch) 237 branch = GitBranch(STABLE_BRANCH_NAME, tracking_branch)
232 if branch.Exists(): 238 if branch.Exists():
233 GitBranch.Checkout(branch) 239 GitBranch.Checkout(branch)
234 branch.Delete() 240 branch.Delete()
235 241
236 242
237 def PushChange(stable_branch, tracking_branch): 243 def PushChange(stable_branch, tracking_branch):
238 """Pushes commits in the stable_branch to the remote git repository. 244 """Pushes commits in the stable_branch to the remote git repository.
239 245
(...skipping 13 matching lines...) Expand all
253 Info('Not work found to push. Exiting') 259 Info('Not work found to push. Exiting')
254 return 260 return
255 261
256 description = _SimpleRunCommand('git log --format=format:%s%n%n%b ' + 262 description = _SimpleRunCommand('git log --format=format:%s%n%n%b ' +
257 tracking_branch + '..') 263 tracking_branch + '..')
258 description = 'Marking set of ebuilds as stable\n\n%s' % description 264 description = 'Marking set of ebuilds as stable\n\n%s' % description
259 Info('Using description %s' % description) 265 Info('Using description %s' % description)
260 merge_branch_name = 'merge_branch' 266 merge_branch_name = 'merge_branch'
261 for push_try in range(num_retries + 1): 267 for push_try in range(num_retries + 1):
262 try: 268 try:
263 _SimpleRunCommand('repo sync .')
264 merge_branch = GitBranch(merge_branch_name, tracking_branch) 269 merge_branch = GitBranch(merge_branch_name, tracking_branch)
265 if merge_branch.Exists(): 270 if merge_branch.Exists():
266 merge_branch.Delete() 271 merge_branch.Delete()
272 _SimpleRunCommand('repo sync .')
267 merge_branch.CreateBranch() 273 merge_branch.CreateBranch()
268 if not merge_branch.Exists(): 274 if not merge_branch.Exists():
269 Die('Unable to create merge branch.') 275 Die('Unable to create merge branch.')
270 _SimpleRunCommand('git merge --squash %s' % stable_branch) 276 _SimpleRunCommand('git merge --squash %s' % stable_branch)
271 _SimpleRunCommand('git commit -m "%s"' % description) 277 _SimpleRunCommand('git commit -m "%s"' % description)
272 _SimpleRunCommand('git config push.default tracking') 278 _SimpleRunCommand('git config push.default tracking')
273 if gflags.FLAGS.dryrun: 279 if gflags.FLAGS.dryrun:
274 _SimpleRunCommand('git push --dry-run') 280 _SimpleRunCommand('git push --dry-run')
275 else: 281 else:
276 _SimpleRunCommand('git push') 282 _SimpleRunCommand('git push')
(...skipping 15 matching lines...) Expand all
292 self.branch_name = branch_name 298 self.branch_name = branch_name
293 self.tracking_branch = tracking_branch 299 self.tracking_branch = tracking_branch
294 300
295 def CreateBranch(self): 301 def CreateBranch(self):
296 GitBranch.Checkout(self) 302 GitBranch.Checkout(self)
297 303
298 @classmethod 304 @classmethod
299 def Checkout(cls, target): 305 def Checkout(cls, target):
300 """Function used to check out to another GitBranch.""" 306 """Function used to check out to another GitBranch."""
301 if target.branch_name == target.tracking_branch or target.Exists(): 307 if target.branch_name == target.tracking_branch or target.Exists():
302 git_cmd = 'git checkout %s' % target.branch_name 308 git_cmd = 'git checkout %s -f' % target.branch_name
303 else: 309 else:
304 git_cmd = 'git checkout -b %s %s' % (target.branch_name, 310 git_cmd = 'git checkout -b %s %s -f' % (target.branch_name,
305 target.tracking_branch) 311 target.tracking_branch)
306 _SimpleRunCommand(git_cmd) 312 _SimpleRunCommand(git_cmd)
307 313
308 def Exists(self): 314 def Exists(self):
309 """Returns True if the branch exists.""" 315 """Returns True if the branch exists."""
310 branch_cmd = 'git branch' 316 branch_cmd = 'git branch'
311 branches = _SimpleRunCommand(branch_cmd) 317 branches = _SimpleRunCommand(branch_cmd)
312 return self.branch_name in branches.split() 318 return self.branch_name in branches.split()
313 319
314 def Delete(self): 320 def Delete(self):
315 """Deletes the branch and returns the user to the master branch. 321 """Deletes the branch and returns the user to the master branch.
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 588
583 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms) 589 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms)
584 if gflags.FLAGS.drop_file: 590 if gflags.FLAGS.drop_file:
585 fh = open(gflags.FLAGS.drop_file, 'w') 591 fh = open(gflags.FLAGS.drop_file, 'w')
586 fh.write(' '.join(revved_packages)) 592 fh.write(' '.join(revved_packages))
587 fh.close() 593 fh.close()
588 594
589 595
590 if __name__ == '__main__': 596 if __name__ == '__main__':
591 main(sys.argv) 597 main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698