),
'help' =>
"Normally under git, a new branch is created and then the patch ".
- "is applied and committed in the new branch. This flag skips the ".
- "branch creation step and applies and commits the patch to the ".
- "current branch.",
+ "is applied and committed in the new branch. This flag ".
+ "cherry-picks the resultant commit onto the original branch and ".
+ "deletes the temporary branch.",
'conflicts' => array(
'update' => true,
),
return true;
}
- private function shouldBranch() {
+ private function canBranch() {
// git only for now
$repository_api = $this->getRepositoryAPI();
if (!($repository_api instanceof ArcanistGitAPI)) {
return false;
}
+ return true;
+ }
+ private function shouldBranch() {
$no_branch = $this->getArgument('nobranch', false);
if ($no_branch) {
return false;
}
-
return true;
}
return $bookmark_name;
}
- private function createBranch(ArcanistBundle $bundle) {
- $branch_name = $this->getBranchName($bundle);
+ private function hasBaseRevision(ArcanistBundle $bundle) {
+ $base_revision = $bundle->getBaseRevision();
$repository_api = $this->getRepositoryAPI();
- $base_revision = $bundle->getBaseRevision();
// verify the base revision is valid
// in a working copy that uses the git-svn bridge, the base revision might
list($err) = $repository_api->execManualLocal(
'cat-file -t %s',
$base_revision);
+ return !$err;
+ }
+
+ private function createBranch(ArcanistBundle $bundle, $has_base_revision) {
+ $branch_name = $this->getBranchName($bundle);
+ $base_revision = $bundle->getBaseRevision();
+ $repository_api = $this->getRepositoryAPI();
- if ($base_revision && !$err) {
+ if ($base_revision && $has_base_revision) {
$repository_api->execxLocal(
'checkout -b %s %s',
$branch_name,
echo phutil_console_format(
"Created and checked out branch %s.\n",
$branch_name);
+
+ return $branch_name;
}
private function createBookmark(ArcanistBundle $bundle) {
$this->updateWorkingCopy();
}
- if ($this->shouldBranch()) {
- $this->createBranch($bundle);
+ $repository_api = $this->getRepositoryAPI();
+
+ $has_base_revision = $this->hasBaseRevision($bundle);
+ if ($this->canBranch() && ($this->shouldBranch() || $has_base_revision)) {
+ $original_branch = $repository_api->getBranchName();
+ $new_branch = $this->createBranch($bundle, $has_base_revision);
}
if ($this->shouldBookmark()) {
$this->createBookmark($bundle);
}
- $repository_api = $this->getRepositoryAPI();
if ($repository_api instanceof ArcanistSubversionAPI) {
$patch_err = 0;
} else {
$verb = 'applied';
}
+
+ if ($this->canBranch() && !$this->shouldBranch() && $has_base_revision) {
+ $repository_api->execxLocal('checkout %s', $original_branch);
+ $ex = null;
+ try {
+ $repository_api->execxLocal('cherry-pick %s', $new_branch);
+ } catch (Exception $ex) {}
+ $repository_api->execxLocal('branch -D %s', $new_branch);
+ if ($ex) {
+ echo phutil_console_format(
+ "\n<bg:red>** Cherry Pick Failed!**</bg>\n");
+ throw $ex;
+ }
+ }
+
echo phutil_console_format(
"<bg:green>** OKAY **</bg> Successfully {$verb} patch.\n");
} else if ($repository_api instanceof ArcanistMercurialAPI) {