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
diff --git a/git_cl.py b/git_cl.py
index 4c91b6c..a4278fc 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -641,6 +641,15 @@
   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 946a39d..a18f59f 100644
--- a/git_common.py
+++ b/git_common.py
@@ -399,7 +399,7 @@
   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)