| Index: cros_mark_as_stable.py
|
| diff --git a/cros_mark_as_stable.py b/cros_mark_as_stable.py
|
| index 8fa635e467ed16f8cca6310e6cbc0387fccc165f..0f4ffeb84a266fe90e5b3d520a8239d48f3a6e80 100755
|
| --- a/cros_mark_as_stable.py
|
| +++ b/cros_mark_as_stable.py
|
| @@ -166,10 +166,15 @@ def _BuildEBuildDictionary(overlays, all, packages):
|
| overlays[overlay].append(ebuild)
|
|
|
|
|
| -def _CheckOnStabilizingBranch(stable_branch):
|
| - """Returns true if the git branch is on the stabilizing branch."""
|
| +def _DoWeHaveLocalCommits(stable_branch, tracking_branch):
|
| + """Returns true if there are local commits."""
|
| current_branch = _SimpleRunCommand('git branch | grep \*').split()[1]
|
| - return current_branch == stable_branch
|
| + if current_branch == stable_branch:
|
| + current_commit_id = _SimpleRunCommand('git rev-parse HEAD')
|
| + tracking_commit_id = _SimpleRunCommand('git rev-parse %s' % tracking_branch)
|
| + return current_commit_id != tracking_commit_id
|
| + else:
|
| + return False
|
|
|
|
|
| def _CheckSaneArguments(package_list, command):
|
| @@ -223,7 +228,10 @@ def Clean(tracking_branch):
|
| tracking_branch: The tracking branch we want to return to after the call.
|
| """
|
| _SimpleRunCommand('git reset HEAD --hard')
|
| - _SimpleRunCommand('git checkout %s' % tracking_branch)
|
| + branch = GitBranch(STABLE_BRANCH_NAME, tracking_branch)
|
| + if branch.Exists():
|
| + GitBranch.Checkout(branch)
|
| + branch.Delete()
|
|
|
|
|
| def PushChange(stable_branch, tracking_branch):
|
| @@ -241,8 +249,8 @@ def PushChange(stable_branch, tracking_branch):
|
| num_retries = 5
|
|
|
| # Sanity check to make sure we're on a stabilizing branch before pushing.
|
| - if not _CheckOnStabilizingBranch(stable_branch):
|
| - Info('Not on branch %s so no work found to push. Exiting' % stable_branch)
|
| + if not _DoWeHaveLocalCommits(stable_branch, tracking_branch):
|
| + Info('Not work found to push. Exiting')
|
| return
|
|
|
| description = _SimpleRunCommand('git log --format=format:%s%n%n%b ' +
|
| @@ -254,6 +262,8 @@ def PushChange(stable_branch, tracking_branch):
|
| try:
|
| _SimpleRunCommand('repo sync .')
|
| merge_branch = GitBranch(merge_branch_name, tracking_branch)
|
| + if merge_branch.Exists():
|
| + merge_branch.Delete()
|
| merge_branch.CreateBranch()
|
| if not merge_branch.Exists():
|
| Die('Unable to create merge branch.')
|
| @@ -283,17 +293,16 @@ class GitBranch(object):
|
| self.tracking_branch = tracking_branch
|
|
|
| def CreateBranch(self):
|
| - """Creates a new git branch or replaces an existing one."""
|
| - if self.Exists():
|
| - self.Delete()
|
| - self._Checkout(self.branch_name)
|
| -
|
| - def _Checkout(self, target, create=True):
|
| - """Function used internally to create and move between branches."""
|
| - if create:
|
| - git_cmd = 'git checkout -b %s %s' % (target, self.tracking_branch)
|
| + GitBranch.Checkout(self)
|
| +
|
| + @classmethod
|
| + def Checkout(cls, target):
|
| + """Function used to check out to another GitBranch."""
|
| + if target.branch_name == target.tracking_branch or target.Exists():
|
| + git_cmd = 'git checkout %s' % target.branch_name
|
| else:
|
| - git_cmd = 'git checkout %s' % target
|
| + git_cmd = 'git checkout -b %s %s' % (target.branch_name,
|
| + target.tracking_branch)
|
| _SimpleRunCommand(git_cmd)
|
|
|
| def Exists(self):
|
| @@ -307,7 +316,8 @@ class GitBranch(object):
|
|
|
| Returns True on success.
|
| """
|
| - self._Checkout(self.tracking_branch, create=False)
|
| + tracking_branch = GitBranch(self.tracking_branch, self.tracking_branch)
|
| + GitBranch.Checkout(tracking_branch)
|
| delete_cmd = 'git branch -D %s' % self.branch_name
|
| _SimpleRunCommand(delete_cmd)
|
|
|
| @@ -570,14 +580,11 @@ def main(argv):
|
| 'and reset the git repo yourself.' % overlay)
|
| raise
|
|
|
| - if revved_packages:
|
| - _CleanStalePackages(gflags.FLAGS.board, new_package_atoms)
|
| - if gflags.FLAGS.drop_file:
|
| - fh = open(gflags.FLAGS.drop_file, 'w')
|
| - fh.write(' '.join(revved_packages))
|
| - fh.close()
|
| - else:
|
| - work_branch.Delete()
|
| + _CleanStalePackages(gflags.FLAGS.board, new_package_atoms)
|
| + if gflags.FLAGS.drop_file:
|
| + fh = open(gflags.FLAGS.drop_file, 'w')
|
| + fh.write(' '.join(revved_packages))
|
| + fh.close()
|
|
|
|
|
| if __name__ == '__main__':
|
|
|