Commit 79706063 authored by sbc@chromium.org's avatar sbc@chromium.org

Add checks to GitSanityChecks (upstream branch or current branch can be None)

I've run in the exceptions a few times when doing
'git cl presubmit' or 'git cl lint' from a detached
HEAD state (not uncommon when using 'git rebase-update')

Review URL: https://codereview.chromium.org/792933003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@293643 0039d316-1c4b-4281-b951-d872f2087c98
parent ae58f93a
......@@ -641,6 +641,15 @@ or verify this branch is set up to track another (via the --track argument to
def GitSanityChecks(self, upstream_git_obj):
"""Checks git repo status and ensures diff is from local commits."""
if upstream_git_obj is None:
if self.GetBranch() is None:
print >> sys.stderr, (
'ERROR: unable to dertermine current branch (detached HEAD?)')
else:
print >> sys.stderr, (
'ERROR: no upstream branch')
return False
# 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()
......
......@@ -399,7 +399,7 @@ def get_or_create_merge_base(branch, parent=None):
base = branch_config(branch, 'base')
base_upstream = branch_config(branch, 'base-upstream')
parent = parent or upstream(branch)
if not parent:
if parent is None or branch is None:
return None
actual_merge_base = run('merge-base', parent, branch)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment