mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Allow checking out branches in arc branch
Summary: The main added value is loading the branch name from revision. Sometimes I know the revision ID but I don't know the branch name. The missing piece is the starting point of the branch. I was thinking about using `arc.land.onto.default` but we also need to get 'origin'. This is also the last step of a simple workflow where underlying VCS is not abstracted away. In future, we can implement this for other APIs. Test Plan: $ arc branch new_branch $ arc branch new_branch $ arc branch D4168 Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4170
This commit is contained in:
parent
955c5b8820
commit
2871d00f96
1 changed files with 53 additions and 0 deletions
|
@ -16,6 +16,7 @@ final class ArcanistBranchWorkflow extends ArcanistBaseWorkflow {
|
|||
public function getCommandSynopses() {
|
||||
return phutil_console_format(<<<EOTEXT
|
||||
**branch** [__options__]
|
||||
**branch** __name__ [__start__]
|
||||
EOTEXT
|
||||
);
|
||||
}
|
||||
|
@ -31,6 +32,10 @@ EOTEXT
|
|||
|
||||
By default, branches that are "Closed" or "Abandoned" are not
|
||||
displayed. You can show them with __--view-all__.
|
||||
|
||||
With __name__, it creates or checks out a branch. If the branch
|
||||
__name__ doesn't exist and is in format D123 then the branch of
|
||||
revision D123 is checked out.
|
||||
EOTEXT
|
||||
);
|
||||
}
|
||||
|
@ -56,6 +61,7 @@ EOTEXT
|
|||
'by-status' => array(
|
||||
'help' => 'Sort branches by status instead of time.',
|
||||
),
|
||||
'*' => 'names',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -66,6 +72,14 @@ EOTEXT
|
|||
'arc branch is only supported under git.');
|
||||
}
|
||||
|
||||
$names = $this->getArgument('names');
|
||||
if ($names) {
|
||||
if (count($names) > 2) {
|
||||
throw new ArcanistUsageException("Specify only one branch.");
|
||||
}
|
||||
return $this->checkoutBranch($names);
|
||||
}
|
||||
|
||||
$branches = $repository_api->getAllBranches();
|
||||
if (!$branches) {
|
||||
throw new ArcanistUsageException('No branches in this working copy.');
|
||||
|
@ -80,6 +94,45 @@ EOTEXT
|
|||
return 0;
|
||||
}
|
||||
|
||||
private function checkoutBranch(array $names) {
|
||||
$api = $this->getRepositoryAPI();
|
||||
|
||||
list($err, $stdout, $stderr) = $api->execManualLocal(
|
||||
'checkout %s',
|
||||
reset($names));
|
||||
|
||||
if ($err) {
|
||||
$match = null;
|
||||
if (preg_match('/^D(\d+)$/', reset($names), $match)) {
|
||||
try {
|
||||
$diff = $this->getConduit()->callMethodSynchronous(
|
||||
'differential.getdiff',
|
||||
array(
|
||||
'revision_id' => $match[1],
|
||||
));
|
||||
|
||||
if ($diff['branch'] != '') {
|
||||
$names[0] = $diff['branch'];
|
||||
list($err, $stdout, $stderr) = $api->execManualLocal(
|
||||
'checkout %s',
|
||||
reset($names));
|
||||
}
|
||||
} catch (ConduitException $ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($err) {
|
||||
list($err, $stdout, $stderr) = $api->execManualLocal(
|
||||
'checkout -b %Ls',
|
||||
$names);
|
||||
}
|
||||
|
||||
echo $stdout;
|
||||
fprintf(STDERR, $stderr);
|
||||
return $err;
|
||||
}
|
||||
|
||||
private function loadCommitInfo(array $branches) {
|
||||
$repository_api = $this->getRepositoryAPI();
|
||||
|
||||
|
|
Loading…
Reference in a new issue