private $useSquash;
private $keepBranch;
private $shouldUpdateWithRebase;
+ private $branchType;
+ private $ontoType;
private $revision;
private $messageFile;
$branch = $this->getBranchOrBookmark();
if ($branch) {
- echo "Landing current branch '{$branch}'.\n";
+ $this->branchType = $this->getBranchType($branch);
+ echo "Landing current {$this->branchType} '{$branch}'.\n";
$branch = array($branch);
}
}
if (count($branch) !== 1) {
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->keepBranch = $this->getArgument('keep-branch');
$this->shouldUpdateWithRebase = $this->getArgument('update-with-rebase');
+ if (!$this->branchType) {
+ $this->branchType = $this->getBranchType($this->branch);
+ }
+
$onto_default = $this->isGit ? 'master' : 'default';
$onto_default = nonempty(
$this->getWorkingCopy()->getConfigFromAnySource('arc.land.onto.default'),
$onto_default);
$this->onto = $this->getArgument('onto', $onto_default);
+ $this->ontoType = $this->getBranchType($this->onto);
$remote_default = $this->isGit ? 'origin' : '';
$this->remote = $this->getArgument('remote', $remote_default);
if ($this->onto == $this->branch) {
$message =
- "You can not land a branch onto itself -- you are trying to land ".
- "'{$this->branch}' onto '{$this->onto}'. For more information on ".
- "how to push changes, see 'Pushing and Closing Revisions' in ".
- "'Arcanist User Guide: arc diff' in the documentation.";
+ "You can not land a {$this->branchType} onto itself -- you are trying".
+ "to land '{$this->branch}' onto '{$this->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->isHistoryImmutable()) {
$message .= " You may be able to 'arc amend' instead.";
}
}
}
- if ($repository_api->isBookmark($this->branch) &&
- !$repository_api->isBookmark($this->onto)) {
- throw new ArcanistUsageException(
- "Source {$this->branch} is a bookmark but destination ".
- "{$this->onto} 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.");
- }
-
- if ($repository_api->isBranch($this->branch) &&
- !$repository_api->isBranch($this->onto)) {
+ if ($this->branchType != $this->ontoType) {
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.");
+ "Source {$this->branch} is a {$this->branchType} but destination ".
+ "{$this->onto} is a {$this->ontoType}. When landing a ".
+ "{$this->branchType}, the destination must also be a ".
+ "{$this->branchType}. Use --onto to specify a {$this->branchType}, ".
+ "or set arc.land.onto.default in .arcconfig.");
}
}
}
echo phutil_console_format(
- "Switched to branch **%s**. Identifying and merging...\n",
+ "Switched to {$this->branchType} **%s**. Identifying and merging...\n",
$this->branch);
}
if (!count($revisions)) {
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 ".
- "to synchronize the branch name and hashes, or use 'arc amend' ".
- "to amend the commit message at HEAD, or use '--revision <id>' ".
- "to select a revision explicitly.");
+ "to synchronize the {$this->branchType} name and hashes, or use ".
+ "'arc amend' to amend the commit message at HEAD, or use ".
+ "'--revision <id>' to select a revision explicitly.");
} else if (count($revisions) > 1) {
$message =
- "There are multiple revisions on feature branch '{$this->branch}' ".
- "which are not present on '{$this->onto}':\n\n".
+ "There are multiple revisions on feature {$this->branchType} ".
+ "'{$this->branch}' which are not present on '{$this->onto}':\n\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.";
throw new ArcanistUsageException($message);
}
if ($local_ahead_of_remote) {
throw new ArcanistUsageException(
- "Local branch '{$this->onto}' is ahead of remote branch ".
- "'{$this->ontoRemoteBranch}', so landing a feature branch ".
- "would push additional changes. Push or reset the changes ".
- "in '{$this->onto}' before running 'arc land'.");
+ "Local {$this->ontoType} '{$this->onto}' is ahead of remote ".
+ "{$this->ontoType} '{$this->ontoRemoteBranch}', so landing a feature ".
+ "{$this->ontoType} would push additional changes. Push or reset the ".
+ "changes in '{$this->onto}' before running 'arc land'.");
}
}
$alt_count = count($alt_branches);
if ($alt_count > 0) {
$input = phutil_console_prompt(
- "Branch {$this->branch} has {$alt_count} branch(s) forking off of it ".
- "that would be deleted during a squash. Would you like to keep a ".
- "non-squashed copy, rebase them on top of {$this->branch}, or abort ".
- "and deal with them yourself? (k)eep, (r)ebase, (a)bort:");
+ ucfirst($this->branchType)." '{$this->branch}' has {$alt_count} ".
+ "{$this->branchType}(s) forking off of it that would be deleted ".
+ "during a squash. Would you like to keep a non-squashed copy, rebase ".
+ "them on top of '{$this->branch}', or abort and deal with them ".
+ "yourself? (k)eep, (r)ebase, (a)bort:");
if ($input == 'k' || $input == 'keep') {
$this->keepBranch = true;
}
} else if ($input == 'a' || $input == 'abort') {
$branch_string = implode("\n", $alt_branches);
- echo "\nRemove the branches starting at these revision and ".
- "run arc land again:\n{$branch_string}\n\n";
+ echo "\nRemove the {$this->branchType}s starting at these revisions ".
+ "and run arc land again:\n{$branch_string}\n\n";
throw new ArcanistUserAbortException();
} else {
throw new ArcanistUsageException("Invalid choice. Aborting arc land.");
private function cleanupBranch() {
$repository_api = $this->getRepositoryAPI();
- echo "Cleaning up feature branch...\n";
+ echo "Cleaning up feature {$this->branchType}...\n";
if ($this->isGit) {
list($ref) = $repository_api->execxLocal(
'rev-parse --verify %s',
$this->branch);
if ($err) {
- echo "No remote feature branch to clean up.\n";
+ echo "No remote feature {$this->branchType} to clean up.\n";
} else {
// NOTE: In Git, you delete a remote branch by pushing it with a
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
'checkout %s',
$this->oldBranch);
echo phutil_console_format(
- "Switched back to branch **%s**.\n",
+ "Switched back to {$this->branchType} **%s**.\n",
$this->oldBranch);
}