1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-23 14:00:55 +01:00

Autocomplete branches to "arc land"

Summary:
  - Add branch name tab completion to "arc land".
  - Default to landing the current branch.
  - This is a little bit hacky but not too terrible. I'm planning to move the whole thing to PhutilArgumentParser at some point so that'll be an opportunity for a big refactor.

Test Plan: Hit tab, landed this branch.

Reviewers: zeeg, btrahan, vrana, jungejason

Reviewed By: btrahan

CC: aran, kdeggelman

Differential Revision: https://secure.phabricator.com/D2293
This commit is contained in:
epriestley 2012-04-23 14:09:29 -07:00
parent dd6ffa4a13
commit 9c4c1de512
3 changed files with 41 additions and 16 deletions

View file

@ -177,6 +177,11 @@ abstract class ArcanistRepositoryAPI {
ConduitClient $conduit, ConduitClient $conduit,
array $query); array $query);
public function getAllBranches() {
// TODO: Implement for Mercurial/SVN and make abstract.
return array();
}
public function hasLocalCommit($commit) { public function hasLocalCommit($commit) {
throw new ArcanistCapabilityNotSupportedException($this); throw new ArcanistCapabilityNotSupportedException($this);
} }

View file

@ -25,7 +25,7 @@ final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
public function getCommandSynopses() { public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT return phutil_console_format(<<<EOTEXT
**land** [__options__] __branch__ [--onto __master__] **land** [__options__] [__branch__] [--onto __master__]
EOTEXT EOTEXT
); );
} }
@ -36,7 +36,8 @@ EOTEXT
Land an accepted change (currently sitting in local feature branch Land an accepted change (currently sitting in local feature branch
__branch__) onto __master__ and push it to the remote. Then, delete __branch__) onto __master__ and push it to the remote. Then, delete
the feature branch. the feature branch. If you omit __branch__, the current branch will
be used.
In mutable repositories, this will perform a --squash merge (the In mutable repositories, this will perform a --squash merge (the
entire branch will be represented by one commit on __master__). In entire branch will be represented by one commit on __master__). In
@ -106,7 +107,20 @@ EOTEXT
} }
public function run() { public function run() {
$repository_api = $this->getRepositoryAPI();
if (!($repository_api instanceof ArcanistGitAPI)) {
throw new ArcanistUsageException("'arc land' only supports git.");
}
$branch = $this->getArgument('branch'); $branch = $this->getArgument('branch');
if (empty($branch)) {
$branch = $repository_api->getBranchName();
if ($branch) {
echo "Landing current branch '{$branch}'.\n";
$branch = array($branch);
}
}
if (count($branch) !== 1) { if (count($branch) !== 1) {
throw new ArcanistUsageException( throw new ArcanistUsageException(
"Specify exactly one branch to land changes from."); "Specify exactly one branch to land changes from.");
@ -128,11 +142,6 @@ EOTEXT
$use_squash = !$this->isHistoryImmutable(); $use_squash = !$this->isHistoryImmutable();
} }
$repository_api = $this->getRepositoryAPI();
if (!($repository_api instanceof ArcanistGitAPI)) {
throw new ArcanistUsageException("'arc land' only supports git.");
}
list($err) = $repository_api->execManualLocal( list($err) = $repository_api->execManualLocal(
'rev-parse --verify %s', 'rev-parse --verify %s',
$branch); $branch);

View file

@ -171,20 +171,31 @@ EOTEXT
$cur = idx($argv, $pos, ''); $cur = idx($argv, $pos, '');
$any_match = false; $any_match = false;
foreach ($output as $possible) {
if (!strncmp($possible, $cur, strlen($cur))) { if (strlen($cur)) {
$any_match = true; foreach ($output as $possible) {
if (!strncmp($possible, $cur, strlen($cur))) {
$any_match = true;
}
} }
} }
if (!$any_match && isset($arguments['*'])) { if (!$any_match && isset($arguments['*'])) {
// TODO: the '*' specifier should probably have more details about // TODO: This is mega hacktown but something else probably breaks
// whether or not it is a list of files. Since it almost always is in // if we use a rich argument specification; fix it when we move to
// practice, assume FILE for now. // PhutilArgumentParser since everything will need to be tested then
echo "FILE\n"; // anyway.
} else { if ($arguments['*'] == 'branch' && isset($repository_api)) {
echo implode(' ', $output)."\n"; $branches = $repository_api->getAllBranches();
$branches = ipull($branches, 'name');
$output = $branches;
} else {
$output = array("FILE");
}
} }
echo implode(' ', $output)."\n";
return 0; return 0;
} }
} }