| Index: git_cl.py
|
| diff --git a/git_cl.py b/git_cl.py
|
| index 2927fd6622c22edb2c01704aed2b752c08170329..9218ebd332b072c00ae48c66eca5f4419312f2fb 100755
|
| --- a/git_cl.py
|
| +++ b/git_cl.py
|
| @@ -828,8 +828,11 @@ def ShortBranchName(branch):
|
|
|
| def GetCurrentBranchRef():
|
| """Returns branch ref (e.g., refs/heads/master) or None."""
|
| - return RunGit(['symbolic-ref', 'HEAD'],
|
| - stderr=subprocess2.VOID, error_ok=True).strip() or None
|
| + ref = RunGit(['symbolic-ref', 'HEAD'],
|
| + stderr=subprocess2.VOID, error_ok=True).strip() or None
|
| + if ref and not ref.startswith('refs/heads/'):
|
| + ref = 'refs/heads/'+ref
|
| + return ref
|
|
|
|
|
| def GetCurrentBranch():
|
| @@ -1112,7 +1115,7 @@ class Changelist(object):
|
| self._remote = (remote, 'refs/remotes/%s/%s' % (remote, branch))
|
| return self._remote
|
|
|
| - def GitSanityChecks(self, upstream_git_obj):
|
| + def GitSanityChecks(self, upstream_git_obj, local_ref='HEAD'):
|
| """Checks git repo status and ensures diff is from local commits."""
|
|
|
| if upstream_git_obj is None:
|
| @@ -1126,8 +1129,8 @@ class Changelist(object):
|
|
|
| # Verify the commit we're diffing against is in our current branch.
|
| upstream_sha = RunGit(['rev-parse', '--verify', upstream_git_obj]).strip()
|
| - common_ancestor = RunGit(['merge-base', upstream_sha, 'HEAD']).strip()
|
| - if upstream_sha != common_ancestor:
|
| + common_anc = RunGit(['merge-base', upstream_sha, local_ref]).strip()
|
| + if upstream_sha != common_anc:
|
| print >> sys.stderr, (
|
| 'ERROR: %s is not in the current branch. You may need to rebase '
|
| 'your tracking branch' % upstream_sha)
|
| @@ -1135,7 +1138,7 @@ class Changelist(object):
|
|
|
| # List the commits inside the diff, and verify they are all local.
|
| commits_in_diff = RunGit(
|
| - ['rev-list', '^%s' % upstream_sha, 'HEAD']).splitlines()
|
| + ['rev-list', '^%s' % upstream_sha, local_ref]).splitlines()
|
| code, remote_branch = RunGitWithCode(['config', 'gitcl.remotebranch'])
|
| remote_branch = remote_branch.strip()
|
| if code != 0:
|
| @@ -1258,7 +1261,8 @@ class Changelist(object):
|
| self.SetPatchset(None)
|
|
|
| def GetChange(self, upstream_branch, author):
|
| - if not self.GitSanityChecks(upstream_branch):
|
| + local_ref = self.GetBranchRef()
|
| + if not self.GitSanityChecks(upstream_branch, local_ref):
|
| DieWithError('\nGit sanity check failure')
|
|
|
| root = settings.GetRelativeRoot()
|
| @@ -1267,10 +1271,10 @@ class Changelist(object):
|
| absroot = os.path.abspath(root)
|
|
|
| # We use the sha1 of HEAD as a name of this change.
|
| - name = RunGitWithCode(['rev-parse', 'HEAD'])[1].strip()
|
| + name = RunGitWithCode(['rev-parse', local_ref])[1].strip()
|
| # Need to pass a relative path for msysgit.
|
| try:
|
| - files = scm.GIT.CaptureStatus([root], '.', upstream_branch)
|
| + files = scm.GIT.CaptureStatus([root], '.', upstream_branch, local_ref)
|
| except subprocess2.CalledProcessError:
|
| DieWithError(
|
| ('\nFailed to diff against upstream branch %s\n\n'
|
| @@ -1288,7 +1292,8 @@ class Changelist(object):
|
| # If the change was never uploaded, use the log messages of all commits
|
| # up to the branch point, as git cl upload will prefill the description
|
| # with these log messages.
|
| - args = ['log', '--pretty=format:%s%n%n%b', '%s...' % (upstream_branch)]
|
| + args = ['log', '--pretty=format:%s%n%n%b',
|
| + '%s...%s' % (upstream_branch, local_ref)]
|
| description = RunGitWithCode(args)[1].strip()
|
|
|
| if not author:
|
| @@ -1301,7 +1306,8 @@ class Changelist(object):
|
| issue,
|
| patchset,
|
| author,
|
| - upstream=upstream_branch)
|
| + upstream=upstream_branch,
|
| + local_ref=local_ref)
|
|
|
| def UpdateDescription(self, description):
|
| self.description = description
|
|
|