From 797060631a486e61dec3bab8b30f35765328660f Mon Sep 17 00:00:00 2001 From: "sbc@chromium.org" Date: Wed, 14 Jan 2015 21:18:12 +0000 Subject: [PATCH] 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 --- git_cl.py | 9 +++++++++ git_common.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/git_cl.py b/git_cl.py index 4c91b6c762..a4278fc217 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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() diff --git a/git_common.py b/git_common.py index 946a39d5d2..a18f59f164 100644 --- a/git_common.py +++ b/git_common.py @@ -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)