]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Switch back to former branch after landing some other branch
authorepriestley <git@epriestley.com>
Fri, 3 Feb 2012 23:44:59 +0000 (15:44 -0800)
committerepriestley <git@epriestley.com>
Fri, 3 Feb 2012 23:44:59 +0000 (15:44 -0800)
Summary:
If you're on A and run "arc land B", run "git checkout A" after
everything's said and done.

Test Plan: Ran "arc land B" from A, got switched back to it.

Reviewers: davidreuss, kdeggelman, btrahan

Reviewed By: btrahan

CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1568

src/workflow/land/ArcanistLandWorkflow.php

index f81f734923f96a7b8e5a6e812cb1519f9ab71abf..76f10da60eb951dfc46699cd8d88ebcf3d7eb024 100644 (file)
@@ -109,6 +109,8 @@ EOTEXT
     $this->requireCleanWorkingCopy();
     $repository_api->parseRelativeLocalCommit(array($remote.'/'.$onto));
 
+    $old_branch = $repository_api->getBranchName();
+
     execx(
       '(cd %s && git checkout %s)',
       $repository_api->getPath(),
@@ -284,6 +286,18 @@ EOTEXT
         $branch);
     }
 
+    // If we were on some branch A and the user ran "arc land B", switch back
+    // to A.
+    if (($old_branch != $branch) && ($old_branch != $onto)) {
+      execx(
+        '(cd %s && git checkout %s)',
+        $repository_api->getPath(),
+        $old_branch);
+      echo phutil_console_format(
+        "Switched back to branch **%s**.\n",
+        $old_branch);
+    }
+
     echo "Done.\n";
 
     return 0;