Chromium Code Reviews| Index: gclient_scm.py |
| diff --git a/gclient_scm.py b/gclient_scm.py |
| index 88760932f2a1c30e5da1aae4c2da9353cea977e3..3015d0d8d4d618a28bb9f5e769b0979b63412e96 100644 |
| --- a/gclient_scm.py |
| +++ b/gclient_scm.py |
| @@ -369,7 +369,8 @@ class GitWrapper(SCMWrapper): |
| verbose = ['--verbose'] |
| printed_path = True |
| - if revision.startswith('refs/'): |
| + remote_ref = scm.GIT.RefToRemoteRef(revision, self.remote) |
| + if revision.startswith('refs/') or remote_ref: |
| rev_type = "branch" |
| elif revision.startswith(self.remote + '/'): |
| # Rewrite remote refs to their local equivalents. |
| @@ -393,8 +394,8 @@ class GitWrapper(SCMWrapper): |
| except subprocess2.CalledProcessError: |
| self._DeleteOrMove(options.force) |
| self._Clone(revision, url, options) |
| - if deps_revision and deps_revision.startswith('branch-heads/'): |
| - deps_branch = deps_revision.replace('branch-heads/', '') |
| + if remote_ref: |
| + deps_branch = remote_ref[1] |
| self._Capture(['branch', deps_branch, deps_revision]) |
| self._Checkout(options, deps_branch, quiet=True) |
| if file_list is not None: |
| @@ -451,12 +452,16 @@ class GitWrapper(SCMWrapper): |
| # 2) current branch is tracking a remote branch with local committed |
| # changes, but the DEPS file switched to point to a hash |
| # - rebase those changes on top of the hash |
| - # 3) current branch is tracking a remote branch w/or w/out changes, |
| - # no switch |
| + # 3) current branch is tracking a remote branch w/or w/out changes, and |
| + # no DEPS switch |
| # - see if we can FF, if not, prompt the user for rebase, merge, or stop |
| - # 4) current branch is tracking a remote branch, switches to a different |
| - # remote branch |
| - # - exit |
| + # 4) current branch is tracking a remote branch, but DEPS switches to a |
| + # different remote branch, and |
| + # a) current branch has no local changes, and --force: |
| + # - checkout new branch |
| + # b) current branch has local changes, and --force and --reset: |
| + # - checkout new branch |
| + # c) otherwise exit |
| # GetUpstreamBranch returns something like 'refs/remotes/origin/master' for |
| # a tracking branch |
| @@ -534,17 +539,38 @@ class GitWrapper(SCMWrapper): |
| newbase=revision, printed_path=printed_path, |
| merge=options.merge) |
| printed_path = True |
| - elif revision.replace('heads', 'remotes/' + self.remote) != upstream_branch: |
| + elif remote_ref and ''.join(remote_ref) != upstream_branch: |
| # case 4 |
| - new_base = revision.replace('heads', 'remotes/' + self.remote) |
| + new_base = ''.join(remote_ref) |
| if not printed_path: |
| self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) |
| - switch_error = ("Switching upstream branch from %s to %s\n" |
| + switch_error = ("Could not switch upstream branch from %s to %s\n" |
| % (upstream_branch, new_base) + |
| - "Please merge or rebase manually:\n" + |
| + "Please use --force or merge or rebase manually:\n" + |
| "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + |
| "OR git checkout -b <some new branch> %s" % new_base) |
| - raise gclient_utils.Error(switch_error) |
| + force_switch = False |
| + if options.force: |
| + try: |
| + self._CheckClean(rev_str) |
| + # case 4a |
| + force_switch = True |
| + except gclient_utils.Error as e: |
| + if options.reset: |
| + # case 4b |
| + force_switch = True |
| + else: |
| + switch_error = '%s\n%s' % (e.message, switch_error) |
| + if force_switch: |
| + self.Print("Switching upstream branch from %s to %s" % |
| + (upstream_branch, new_base)) |
| + switch_branch = 'gclient_' + remote_ref[1] |
| + self._Capture(['branch', '-f', switch_branch, new_base]) |
| + self._Checkout(options, switch_branch, force=True, quiet=True) |
| + pass |
|
iannucci
2014/09/06 20:01:29
pass not needed?
Michael Moss
2014/09/08 23:58:42
Done.
|
| + else: |
| + # case 4c |
| + raise gclient_utils.Error(switch_error) |
|
iannucci
2014/09/06 20:01:29
why not raise this directly in the else case above
Michael Moss
2014/09/08 23:58:43
That's in the options.force block, so it would nev
|
| else: |
| # case 3 - the default case |
| if files is not None: |