Chromium Code Reviews| Index: scm.py |
| diff --git a/scm.py b/scm.py |
| index eb5c52403c3e2595d14b133a7d0d00e289811d10..9cefd73d6e7208a2f494550c7fa0580b0568d817 100644 |
| --- a/scm.py |
| +++ b/scm.py |
| @@ -353,11 +353,35 @@ 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). |
|
iannucci
2014/09/06 20:01:29
one thing we should /seriously/ consider in gclien
|
| + 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/)?heads/', 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 |