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,
array $query);
public function getAllBranches() {
// TODO: Implement for Mercurial/SVN and make abstract.
return array();
}
public function hasLocalCommit($commit) {
throw new ArcanistCapabilityNotSupportedException($this);
}

View file

@ -25,7 +25,7 @@ final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**land** [__options__] __branch__ [--onto __master__]
**land** [__options__] [__branch__] [--onto __master__]
EOTEXT
);
}
@ -36,7 +36,8 @@ EOTEXT
Land an accepted change (currently sitting in local feature branch
__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
entire branch will be represented by one commit on __master__). In
@ -106,7 +107,20 @@ EOTEXT
}
public function run() {
$repository_api = $this->getRepositoryAPI();
if (!($repository_api instanceof ArcanistGitAPI)) {
throw new ArcanistUsageException("'arc land' only supports git.");
}
$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) {
throw new ArcanistUsageException(
"Specify exactly one branch to land changes from.");
@ -128,11 +142,6 @@ EOTEXT
$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(
'rev-parse --verify %s',
$branch);

View file

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