]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Make arc land list the commits being landed.
authordurham <durham@fb.com>
Fri, 29 Mar 2013 17:08:23 +0000 (10:08 -0700)
committerdurham <durham@fb.com>
Fri, 29 Mar 2013 17:08:23 +0000 (10:08 -0700)
Summary:
Arc land is a bit magical and some users have gotten bitten by
the fact that it collapses and lands every commit on the branch. To make
it explicit what is being landed, it now shows a list of the commits
that are being landed.  I also added a --preview flag that will just
print the commits that would be landed, but does nothing else.

Hopefully this make arc land a little less magical for people.

Test Plan:
arc land in the following scenarios:
- Landing one change
- Landing no changes
- Landing a stack of changes

Did it with hg and git.

Reviewers: epriestley

Reviewed By: epriestley

CC: nh, sid0, dschleimer, bos, aran, Korvin
Differential Revision: https://secure.phabricator.com/D5460

src/workflow/ArcanistLandWorkflow.php

index 21e1e2e23b8596bd158d16c92e0f86177807b10e..bc2961c66f733d672e3fa8fd4f3096bfff85b054 100644 (file)
@@ -21,6 +21,7 @@ final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
   private $shouldUpdateWithRebase;
   private $branchType;
   private $ontoType;
+  private $preview;
 
   private $revision;
   private $messageFile;
@@ -131,6 +132,10 @@ EOTEXT
         'help'  => 'Use the message from a specific revision, rather than '.
                    'inferring the revision based on branch content.',
       ),
+      'preview' => array(
+        'help' => 'Prints the commits that would be landed. Does not actually '.
+                  'modify or land the commits.'
+      ),
       '*' => 'branch',
     );
   }
@@ -146,6 +151,12 @@ EOTEXT
       throw $ex;
     }
 
+    $this->printPendingCommits();
+    if ($this->preview) {
+      $this->restoreBranch();
+      return 0;
+    }
+
     $this->checkoutBranch();
     $this->findRevision();
 
@@ -212,6 +223,7 @@ EOTEXT
     $this->branch = head($branch);
     $this->keepBranch = $this->getArgument('keep-branch');
     $this->shouldUpdateWithRebase = $this->getArgument('update-with-rebase');
+    $this->preview = $this->getArgument('preview');
 
     if (!$this->branchType) {
       $this->branchType = $this->getBranchType($this->branch);
@@ -306,6 +318,42 @@ EOTEXT
       $this->branch);
   }
 
+  private function printPendingCommits() {
+    $repository_api = $this->getRepositoryAPI();
+
+    if ($repository_api instanceof ArcanistGitAPI) {
+      list($out) = $repository_api->execxLocal(
+        'log --oneline %s ^%s',
+        $this->branch,
+        $this->onto);
+    } else if ($repository_api instanceof ArcanistMercurialAPI) {
+      $common_ancestor = $repository_api->getCanonicalRevisionName(
+        hgsprintf('ancestor(%s,%s)',
+          $this->onto,
+          $this->branch));
+
+      $branch_range = hgsprintf(
+        'reverse((%s::%s) - %s)',
+        $common_ancestor,
+        $this->branch,
+        $common_ancestor);
+
+      list($out) = $repository_api->execxLocal(
+        'log -r %s --template %s',
+        $branch_range,
+        '{node|short} {desc|firstline}\n');
+    }
+
+    if (!trim($out)) {
+      $this->restoreBranch();
+      throw new ArcanistUsageException(
+          "No commits to land from {$this->branch}.");
+    }
+
+    echo phutil_console_format(
+      "The following commit(s) will be landed:\n\n{$out}\n");
+  }
+
   private function findRevision() {
     $repository_api = $this->getRepositoryAPI();