]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow hg arc land when no rebase is necessary
authordurham <durham@fb.com>
Tue, 22 Jan 2013 22:29:00 +0000 (14:29 -0800)
committerdurham <durham@fb.com>
Tue, 22 Jan 2013 23:20:10 +0000 (15:20 -0800)
Summary:
Previously, trying to arc land in a mercurial repo would
fail if the local branch was already at the tip of the onto branch
(since hg rebase exited with code 1).  This change makes it check
if a rebase is needed before executing the rebase.

Test Plan:
hg init foo
cd foo
hg bookmark master
touch a && hg add a && hg commit -ma
// setup your .arcconfig
cd ..
hg clone foo foo2
cd foo2
hg bookmark mybook
touch b && hg add b && hg commit -mb
arc land --onto master --revision <your rev number>

Arc land should succeed.  I also tried landing when a rebase was
necessary and it still worked.

Reviewers: epriestley, dschleimer, bos

Reviewed By: epriestley

CC: sid0, aran, Korvin
Differential Revision: https://secure.phabricator.com/D4588

src/workflow/ArcanistLandWorkflow.php

index b9903c8a42e3477afc54b299b38e4f6fa2aafdec..c651376b6f98c9095b051e3e4b3a7eb93ceaa983 100644 (file)
@@ -470,17 +470,26 @@ EOTEXT
         }
       }
     } else if ($this->isHg) {
-      // keep branch here so later we can decide whether to remove it
-      $err = $repository_api->execPassthru(
-        'rebase -d %s --keepbranches',
-        $this->onto);
-      if ($err) {
-        throw new ArcanistUsageException(
-          "'hg rebase {$this->onto}' failed. ".
-          "You can abort with 'hg rebase --abort', ".
-          "or resolve conflicts and use 'hg rebase ".
-          "--continue' to continue forward. After resolving the rebase, ".
-          "run 'arc land' again.");
+      $onto_tip = $repository_api->getCanonicalRevisionName($this->onto);
+      $common_ancestor = $repository_api->getCanonicalRevisionName(
+        sprintf("ancestor('%s','%s')",
+          $this->onto,
+          $this->branch));
+
+      // Only rebase if the local branch is not at the tip of the onto branch.
+      if ($onto_tip != $common_ancestor) {
+        // keep branch here so later we can decide whether to remove it
+        $err = $repository_api->execPassthru(
+          'rebase -d %s --keepbranches',
+          $this->onto);
+        if ($err) {
+          throw new ArcanistUsageException(
+            "'hg rebase {$this->onto}' failed. ".
+            "You can abort with 'hg rebase --abort', ".
+            "or resolve conflicts and use 'hg rebase ".
+            "--continue' to continue forward. After resolving the rebase, ".
+            "run 'arc land' again.");
+        }
       }
     }