From: epriestley Date: Thu, 10 May 2012 19:14:53 +0000 (-0700) Subject: arc land: add --delete-remote, raise an error for landing a branch onto itself X-Git-Tag: conduit-4~9 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=86ead1b8f1573b5dcdc7ce037228f1f724e37b4b;p=arcanist.git arc land: add --delete-remote, raise an error for landing a branch onto itself 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 --- diff --git a/src/workflow/land/ArcanistLandWorkflow.php b/src/workflow/land/ArcanistLandWorkflow.php index 07849567..5a295aa2 100644 --- a/src/workflow/land/ArcanistLandWorkflow.php +++ b/src/workflow/land/ArcanistLandWorkflow.php @@ -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 : + + 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