mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 08:42:40 +01:00
Use bookmark terminology if arc land
on hg bookmark
Summary: Changes message for `arc land` that displays current branch or bookmark (if none is specified) to appropriately use the term 'bookmark' when on a bookmark in an hg repository. Test Plan: Ran `arc land` on new git and hg repositories, checking for correct identification of 'branch' or 'bookmark'. ~/test$ mkdir hg-test ~/test$ mkdir git-test ~/test$ cd hg-test ~/test/hg-test$ hg init ~/test/hg-test$ hg branch default ~/test/hg-test$ hg bookmarks no bookmarks set ~/test/hg-test$ arc land Landing current branch 'default'. Usage Exception: You can not land a branch onto itself -- you are trying to land 'default' onto 'default'. For more information on how to push changes, see 'Pushing and Closing Revisions' in 'Arcanist User Guide: arc diff' in the documentation. You may be able to 'arc amend' instead. ~/test/hg-test$ hg bookmark testmark ~/test/hg-test$ hg bookmarks * testmark -1:000000000000 ~/test/hg-test$ hg branch default ~/test/hg-test$ arc land Landing current bookmark 'testmark'. Usage Exception: Source testmark is a bookmark but destination default is not a bookmark. When landing a bookmark, the destination must also be a bookmark. Use --onto to specify a bookmark, or set arc.land.onto.default in .arcconfig. Confirm still works on a git branch: ~/test/hg-test$ cd ../git-test/ ~/test/git-test$ ls ~/test/git-test$ git init Initialized empty Git repository in ~/test/git-test/.git/ ~/test/git-test$ touch testfile ~/test/git-test$ git commit -am 'Test file' ~/test/git-test$ git branch * master ~/test/git-test$ arc land Landing current branch 'master'. Usage Exception: You can not land a branch onto itself -- you are trying to land 'master' onto 'master'. For more information on how to push changes, see 'Pushing and Closing Revisions' in 'Arcanist User Guide: arc diff' in the documentation. You may be able to 'arc amend' instead. Reviewers: DurhamGoode, epriestley Reviewed By: DurhamGoode CC: aran, epriestley, Korvin Differential Revision: https://secure.phabricator.com/D5163
This commit is contained in:
parent
2e87419c7b
commit
0e254f769d
1 changed files with 49 additions and 42 deletions
|
@ -19,6 +19,8 @@ final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
|
||||||
private $useSquash;
|
private $useSquash;
|
||||||
private $keepBranch;
|
private $keepBranch;
|
||||||
private $shouldUpdateWithRebase;
|
private $shouldUpdateWithRebase;
|
||||||
|
private $branchType;
|
||||||
|
private $ontoType;
|
||||||
|
|
||||||
private $revision;
|
private $revision;
|
||||||
private $messageFile;
|
private $messageFile;
|
||||||
|
@ -197,24 +199,30 @@ EOTEXT
|
||||||
$branch = $this->getBranchOrBookmark();
|
$branch = $this->getBranchOrBookmark();
|
||||||
|
|
||||||
if ($branch) {
|
if ($branch) {
|
||||||
echo "Landing current branch '{$branch}'.\n";
|
$this->branchType = $this->getBranchType($branch);
|
||||||
|
echo "Landing current {$this->branchType} '{$branch}'.\n";
|
||||||
$branch = array($branch);
|
$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 or bookmark to land changes from.");
|
||||||
}
|
}
|
||||||
$this->branch = head($branch);
|
$this->branch = head($branch);
|
||||||
$this->keepBranch = $this->getArgument('keep-branch');
|
$this->keepBranch = $this->getArgument('keep-branch');
|
||||||
$this->shouldUpdateWithRebase = $this->getArgument('update-with-rebase');
|
$this->shouldUpdateWithRebase = $this->getArgument('update-with-rebase');
|
||||||
|
|
||||||
|
if (!$this->branchType) {
|
||||||
|
$this->branchType = $this->getBranchType($this->branch);
|
||||||
|
}
|
||||||
|
|
||||||
$onto_default = $this->isGit ? 'master' : 'default';
|
$onto_default = $this->isGit ? 'master' : 'default';
|
||||||
$onto_default = nonempty(
|
$onto_default = nonempty(
|
||||||
$this->getWorkingCopy()->getConfigFromAnySource('arc.land.onto.default'),
|
$this->getWorkingCopy()->getConfigFromAnySource('arc.land.onto.default'),
|
||||||
$onto_default);
|
$onto_default);
|
||||||
$this->onto = $this->getArgument('onto', $onto_default);
|
$this->onto = $this->getArgument('onto', $onto_default);
|
||||||
|
$this->ontoType = $this->getBranchType($this->onto);
|
||||||
|
|
||||||
$remote_default = $this->isGit ? 'origin' : '';
|
$remote_default = $this->isGit ? 'origin' : '';
|
||||||
$this->remote = $this->getArgument('remote', $remote_default);
|
$this->remote = $this->getArgument('remote', $remote_default);
|
||||||
|
@ -242,10 +250,10 @@ EOTEXT
|
||||||
|
|
||||||
if ($this->onto == $this->branch) {
|
if ($this->onto == $this->branch) {
|
||||||
$message =
|
$message =
|
||||||
"You can not land a branch onto itself -- you are trying to land ".
|
"You can not land a {$this->branchType} onto itself -- you are trying".
|
||||||
"'{$this->branch}' onto '{$this->onto}'. For more information on ".
|
"to land '{$this->branch}' onto '{$this->onto}'. For more".
|
||||||
"how to push changes, see 'Pushing and Closing Revisions' in ".
|
"information on how to push changes, see 'Pushing and Closing".
|
||||||
"'Arcanist User Guide: arc diff' in the documentation.";
|
"Revisions' in 'Arcanist User Guide: arc diff' in the documentation.";
|
||||||
if (!$this->isHistoryImmutable()) {
|
if (!$this->isHistoryImmutable()) {
|
||||||
$message .= " You may be able to 'arc amend' instead.";
|
$message .= " You may be able to 'arc amend' instead.";
|
||||||
}
|
}
|
||||||
|
@ -261,22 +269,13 @@ EOTEXT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($repository_api->isBookmark($this->branch) &&
|
if ($this->branchType != $this->ontoType) {
|
||||||
!$repository_api->isBookmark($this->onto)) {
|
|
||||||
throw new ArcanistUsageException(
|
throw new ArcanistUsageException(
|
||||||
"Source {$this->branch} is a bookmark but destination ".
|
"Source {$this->branch} is a {$this->branchType} but destination ".
|
||||||
"{$this->onto} is not a bookmark. When landing a bookmark, ".
|
"{$this->onto} is a {$this->ontoType}. When landing a ".
|
||||||
"the destination must also be a bookmark. Use --onto to specify ".
|
"{$this->branchType}, the destination must also be a ".
|
||||||
"a bookmark, or set arc.land.onto.default in .arcconfig.");
|
"{$this->branchType}. Use --onto to specify a {$this->branchType}, ".
|
||||||
}
|
"or set arc.land.onto.default in .arcconfig.");
|
||||||
|
|
||||||
if ($repository_api->isBranch($this->branch) &&
|
|
||||||
!$repository_api->isBranch($this->onto)) {
|
|
||||||
throw new ArcanistUsageException(
|
|
||||||
"Source {$this->branch} is a branch but destination {$this->onto} ".
|
|
||||||
"is not a branch. When landing a branch, the destination must also ".
|
|
||||||
"be a branch. Use --onto to specify a branch, or set ".
|
|
||||||
"arc.land.onto.default in .arcconfig.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +302,7 @@ EOTEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
echo phutil_console_format(
|
echo phutil_console_format(
|
||||||
"Switched to branch **%s**. Identifying and merging...\n",
|
"Switched to {$this->branchType} **%s**. Identifying and merging...\n",
|
||||||
$this->branch);
|
$this->branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,17 +332,17 @@ EOTEXT
|
||||||
|
|
||||||
if (!count($revisions)) {
|
if (!count($revisions)) {
|
||||||
throw new ArcanistUsageException(
|
throw new ArcanistUsageException(
|
||||||
"arc can not identify which revision exists on branch ".
|
"arc can not identify which revision exists on {$this->branchType} ".
|
||||||
"'{$this->branch}'. Update the revision with recent changes ".
|
"'{$this->branch}'. Update the revision with recent changes ".
|
||||||
"to synchronize the branch name and hashes, or use 'arc amend' ".
|
"to synchronize the {$this->branchType} name and hashes, or use ".
|
||||||
"to amend the commit message at HEAD, or use '--revision <id>' ".
|
"'arc amend' to amend the commit message at HEAD, or use ".
|
||||||
"to select a revision explicitly.");
|
"'--revision <id>' to select a revision explicitly.");
|
||||||
} else if (count($revisions) > 1) {
|
} else if (count($revisions) > 1) {
|
||||||
$message =
|
$message =
|
||||||
"There are multiple revisions on feature branch '{$this->branch}' ".
|
"There are multiple revisions on feature {$this->branchType} ".
|
||||||
"which are not present on '{$this->onto}':\n\n".
|
"'{$this->branch}' which are not present on '{$this->onto}':\n\n".
|
||||||
$this->renderRevisionList($revisions)."\n".
|
$this->renderRevisionList($revisions)."\n".
|
||||||
"Separate these revisions onto different branches, or use ".
|
"Separate these revisions onto different {$this->branchType}s, or use ".
|
||||||
"'--revision <id>' to select one.";
|
"'--revision <id>' to select one.";
|
||||||
throw new ArcanistUsageException($message);
|
throw new ArcanistUsageException($message);
|
||||||
}
|
}
|
||||||
|
@ -464,10 +463,10 @@ EOTEXT
|
||||||
|
|
||||||
if ($local_ahead_of_remote) {
|
if ($local_ahead_of_remote) {
|
||||||
throw new ArcanistUsageException(
|
throw new ArcanistUsageException(
|
||||||
"Local branch '{$this->onto}' is ahead of remote branch ".
|
"Local {$this->ontoType} '{$this->onto}' is ahead of remote ".
|
||||||
"'{$this->ontoRemoteBranch}', so landing a feature branch ".
|
"{$this->ontoType} '{$this->ontoRemoteBranch}', so landing a feature ".
|
||||||
"would push additional changes. Push or reset the changes ".
|
"{$this->ontoType} would push additional changes. Push or reset the ".
|
||||||
"in '{$this->onto}' before running 'arc land'.");
|
"changes in '{$this->onto}' before running 'arc land'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,10 +669,11 @@ EOTEXT
|
||||||
$alt_count = count($alt_branches);
|
$alt_count = count($alt_branches);
|
||||||
if ($alt_count > 0) {
|
if ($alt_count > 0) {
|
||||||
$input = phutil_console_prompt(
|
$input = phutil_console_prompt(
|
||||||
"Branch {$this->branch} has {$alt_count} branch(s) forking off of it ".
|
ucfirst($this->branchType)." '{$this->branch}' has {$alt_count} ".
|
||||||
"that would be deleted during a squash. Would you like to keep a ".
|
"{$this->branchType}(s) forking off of it that would be deleted ".
|
||||||
"non-squashed copy, rebase them on top of {$this->branch}, or abort ".
|
"during a squash. Would you like to keep a non-squashed copy, rebase ".
|
||||||
"and deal with them yourself? (k)eep, (r)ebase, (a)bort:");
|
"them on top of '{$this->branch}', or abort and deal with them ".
|
||||||
|
"yourself? (k)eep, (r)ebase, (a)bort:");
|
||||||
|
|
||||||
if ($input == 'k' || $input == 'keep') {
|
if ($input == 'k' || $input == 'keep') {
|
||||||
$this->keepBranch = true;
|
$this->keepBranch = true;
|
||||||
|
@ -686,8 +686,8 @@ EOTEXT
|
||||||
}
|
}
|
||||||
} else if ($input == 'a' || $input == 'abort') {
|
} else if ($input == 'a' || $input == 'abort') {
|
||||||
$branch_string = implode("\n", $alt_branches);
|
$branch_string = implode("\n", $alt_branches);
|
||||||
echo "\nRemove the branches starting at these revision and ".
|
echo "\nRemove the {$this->branchType}s starting at these revisions ".
|
||||||
"run arc land again:\n{$branch_string}\n\n";
|
"and run arc land again:\n{$branch_string}\n\n";
|
||||||
throw new ArcanistUserAbortException();
|
throw new ArcanistUserAbortException();
|
||||||
} else {
|
} else {
|
||||||
throw new ArcanistUsageException("Invalid choice. Aborting arc land.");
|
throw new ArcanistUsageException("Invalid choice. Aborting arc land.");
|
||||||
|
@ -805,7 +805,7 @@ EOTEXT
|
||||||
private function cleanupBranch() {
|
private function cleanupBranch() {
|
||||||
$repository_api = $this->getRepositoryAPI();
|
$repository_api = $this->getRepositoryAPI();
|
||||||
|
|
||||||
echo "Cleaning up feature branch...\n";
|
echo "Cleaning up feature {$this->branchType}...\n";
|
||||||
if ($this->isGit) {
|
if ($this->isGit) {
|
||||||
list($ref) = $repository_api->execxLocal(
|
list($ref) = $repository_api->execxLocal(
|
||||||
'rev-parse --verify %s',
|
'rev-parse --verify %s',
|
||||||
|
@ -830,7 +830,7 @@ EOTEXT
|
||||||
$this->branch);
|
$this->branch);
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
echo "No remote feature branch to clean up.\n";
|
echo "No remote feature {$this->branchType} to clean up.\n";
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// NOTE: In Git, you delete a remote branch by pushing it with a
|
// NOTE: In Git, you delete a remote branch by pushing it with a
|
||||||
|
@ -875,6 +875,13 @@ EOTEXT
|
||||||
return $branch;
|
return $branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getBranchType($branch) {
|
||||||
|
$repository_api = $this->getRepositoryAPI();
|
||||||
|
if ($this->isHg && $repository_api->isBookmark($branch)) {
|
||||||
|
return "bookmark";
|
||||||
|
}
|
||||||
|
return "branch";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore the original branch, e.g. after a successful land or a failed
|
* Restore the original branch, e.g. after a successful land or a failed
|
||||||
|
@ -886,7 +893,7 @@ EOTEXT
|
||||||
'checkout %s',
|
'checkout %s',
|
||||||
$this->oldBranch);
|
$this->oldBranch);
|
||||||
echo phutil_console_format(
|
echo phutil_console_format(
|
||||||
"Switched back to branch **%s**.\n",
|
"Switched back to {$this->branchType} **%s**.\n",
|
||||||
$this->oldBranch);
|
$this->oldBranch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue