]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Try switching to the branch of the same name, instead of detached head
authorAlex Vandiver <alexmv@dropbox.com>
Fri, 20 Nov 2015 18:55:37 +0000 (10:55 -0800)
committerAlex Vandiver <alexmv@dropbox.com>
Fri, 20 Nov 2015 18:58:37 +0000 (10:58 -0800)
Summary:
Landing from a branch that directly tracks origin/master places one in
a detached HEAD state.  Instead, examine if there is a local branch of
the name that we landed onto, that also tracks the upstream; if so,
switch to that.

Test Plan:
Made a branch via `git checkout -b testing origin/master`
and tried to `arc land`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T9723

Differential Revision: https://secure.phabricator.com/D14420

src/land/ArcanistGitLandEngine.php

index 95b33aa1f05739b2480c5be190932abe242ea19d..7256b05021e920ba6b9e38039d8c60fbff820a44 100644 (file)
@@ -262,13 +262,26 @@ final class ArcanistGitLandEngine
         $path->removeUpstream($local_branch);
 
         if (!$path->getLength()) {
-          $this->writeInfo(
-            pht('UPDATE'),
-            pht(
-              'Local branch "%s" directly tracks remote, staying on '.
-              'detached HEAD.',
-              $local_branch));
-          return;
+          // The local branch tracked upstream directly; however, it
+          // may not be the only one to do so.  If there's a local
+          // branch of the same name that tracks the remote, try
+          // switching to that.
+          $local_branch = $this->getTargetOnto();
+          list($err) = $api->execManualLocal(
+            'rev-parse --verify %s',
+            $local_branch);
+          if (!$err) {
+            $path = $api->getPathToUpstream($local_branch);
+          }
+          if (!$path->isConnectedToRemote()) {
+            $this->writeInfo(
+              pht('UPDATE'),
+              pht(
+                'Local branch "%s" directly tracks remote, staying on '.
+                'detached HEAD.',
+                $local_branch));
+            return;
+          }
         }
 
         $local_branch = head($path->getLocalBranches());