]> khamidou — GitHub mirrors - arcanist.git/commitdiff
arc land: add --delete-remote, raise an error for landing a branch onto itself
authorepriestley <git@epriestley.com>
Thu, 10 May 2012 19:14:53 +0000 (12:14 -0700)
committerepriestley <git@epriestley.com>
Thu, 10 May 2012 19:14:53 +0000 (12:14 -0700)
Summary:
  - Allow users to delete the remote copy of a feature branch as well as the local one, for workflows that push feature branches. We test if the remote exists before trying to delete it.
  - Raise a better warning when you misuse "arc land".
  - I also wrote some documentation about this, see next diff.

Test Plan:
  - Tried to land a branch onto itself.
  - Ran "arc land --delete-remote" on feature branches with and without remote feature branches.

Reviewers: aurelijus, btrahan

Reviewed By: aurelijus

CC: aran
Maniphest Tasks: T1204

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

src/workflow/land/ArcanistLandWorkflow.php

index 07849567aa11d3e259ff725209e3712bfa7f73f1..5a295aa24ff239059c0202c9bb157a648e34144a 100644 (file)
@@ -97,6 +97,13 @@ EOTEXT
           'merge' => '--merge and --squash are conflicting merge strategies.',
         ),
       ),
+      'delete-remote' => array(
+        'help'      => 'Delete the feature branch in the remote after '.
+                       'landing it.',
+        'conflicts' => array(
+          'keep-branch' => true,
+        ),
+      ),
       'revision' => array(
         'param' => 'id',
         'help'  => 'Use the message from a specific revision, rather than '.
@@ -134,6 +141,14 @@ EOTEXT
     $remote = $this->getArgument('remote', 'origin');
     $onto = $this->getArgument('onto', $onto_default);
 
+    if ($onto == $branch) {
+      throw new ArcanistUsageException(
+        "You can not land a branch onto itself -- you are trying to land ".
+        "'{$branch}' onto '{$onto}'. For more information on how to push ".
+        "changes, see 'Pushing and Closing Revisions' in ".
+        "'Arcanist User Guide: arc diff' in the documentation.");
+    }
+
     if ($this->getArgument('merge')) {
       $use_squash = false;
     } else if ($this->getArgument('squash')) {
@@ -327,6 +342,29 @@ EOTEXT
       $repository_api->execxLocal(
         'branch -D %s',
         $branch);
+
+      if ($this->getArgument('delete-remote')) {
+        list($err, $ref) = $repository_api->execManualLocal(
+          'rev-parse --verify %s/%s',
+          $remote,
+          $branch);
+
+        if ($err) {
+          echo "No remote feature branch to clean up.\n";
+        } else {
+
+          // NOTE: In Git, you delete a remote branch by pushing it with a
+          // colon in front of its name:
+          //
+          //   git push <remote> :<branch>
+
+          echo "Cleaning up remote feature branch...\n";
+          $repository_api->execxLocal(
+            'push %s :%s',
+            $remote,
+            $branch);
+        }
+      }
     }
 
     // If we were on some branch A and the user ran "arc land B", switch back