Abort `git cl push` if pushing into a local branch.

R=agable@chromium.org, szager@chromium.org
BUG=338102

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@263202 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cl.py b/git_cl.py
index 9dabe20..f2f3434 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -1744,7 +1744,7 @@
 def SendUpstream(parser, args, cmd):
   """Common code for CmdPush and CmdDCommit
 
-  Squashed commit into a single.
+  Squashes branch into a single commit.
   Updates changelog with metadata (e.g. pointer to review).
   Pushes/dcommits the code upstream.
   Updates review and closes.
@@ -1763,6 +1763,21 @@
   (options, args) = parser.parse_args(args)
   cl = Changelist()
 
+  current = cl.GetBranch()
+  remote, upstream_branch = cl.FetchUpstreamTuple(cl.GetBranch())
+  if not settings.GetIsGitSvn() and remote == '.':
+    print
+    print 'Attempting to push branch %r into another local branch!' % current
+    print
+    print 'Either reparent this branch on top of origin/master:'
+    print '  git reparent-branch --root'
+    print
+    print 'OR run `git rebase-update` if you think the parent branch is already'
+    print 'committed.'
+    print
+    print '  Current parent: %r' % upstream_branch
+    return 1
+
   if not args or cmd == 'push':
     # Default to merging against our best guess of the upstream branch.
     args = [cl.GetUpstreamBranch()]
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 65da4df..9234fb2 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -270,6 +270,9 @@
       ((['git',
          'config', 'branch.working.merge'],), 'refs/heads/master'),
       ((['git', 'config', 'branch.working.remote'],), 'origin'),
+      ((['git', 'config', 'branch.working.merge'],),
+       'refs/heads/master'),
+      ((['git', 'config', 'branch.working.remote'],), 'origin'),
       ((['git', 'rev-list', '--merges',
          '--grep=^SVN changes up to revision [0-9]*$',
          'refs/remotes/origin/master^!'],), ''),