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

Unified Diff: scm.py

Issue 549733002: Fix gclient branch ref mangling and allow --force branch switches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: lint Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gclient_scm.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scm.py
diff --git a/scm.py b/scm.py
index eb5c52403c3e2595d14b133a7d0d00e289811d10..9bc96bc8055832707a749d3b9d256766b5a43956 100644
--- a/scm.py
+++ b/scm.py
@@ -353,11 +353,34 @@ class GIT(object):
return remote, upstream_branch
@staticmethod
+ def RefToRemoteRef(ref, remote=None):
+ """Convert a checkout ref to the equivalent remote ref.
+
+ Returns:
+ A tuple of the remote ref's (common prefix, unique suffix), or None if it
+ doesn't appear to refer to a remote ref (e.g. it's a commit hash).
+ """
+ # TODO(mmoss): This is just a brute-force mapping based of the expected git
+ # config. It's a bit better than the even more brute-force replace('heads',
+ # ...), but could still be smarter (like maybe actually using values gleaned
+ # from the git config).
+ m = re.match('^(refs/(remotes/)?)?branch-heads/', ref or '')
+ if m:
+ return ('refs/remotes/branch-heads/', ref.replace(m.group(0), ''))
+ if remote:
+ m = re.match('^((refs/)?remotes/)?%s/|(refs/)?heads/' % remote, ref or '')
+ if m:
+ return ('refs/remotes/%s/' % remote, ref.replace(m.group(0), ''))
+ return None
+
+ @staticmethod
def GetUpstreamBranch(cwd):
"""Gets the current branch's upstream branch."""
remote, upstream_branch = GIT.FetchUpstreamTuple(cwd)
if remote != '.' and upstream_branch:
- upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote)
+ remote_ref = GIT.RefToRemoteRef(upstream_branch, remote)
+ if remote_ref:
+ upstream_branch = ''.join(remote_ref)
return upstream_branch
@staticmethod
« no previous file with comments | « gclient_scm.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698