1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-29 10:12:41 +01:00

Use git-cherry-pick for arc patch

Summary:
This changes what --nobranch does, though not what it means.  In git, the patch
is applied to the git commit it is based off where it will commit cleanly, and
if you specify --nobranch then arc-patch will then switch back to your original
branch and try to cherry-pick the commit there.

If this fails, you end up with merge-conflict markers in the file which can be
handy.

Test Plan: https://secure.phabricator.com/P572

Reviewers: epriestley, btrahan

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3712
This commit is contained in:
Edward Speyer 2012-10-16 16:46:21 -07:00
parent a850f1c6ef
commit 2d269aefed

View file

@ -111,9 +111,9 @@ EOTEXT
), ),
'help' => 'help' =>
"Normally under git, a new branch is created and then the patch ". "Normally under git, a new branch is created and then the patch ".
"is applied and committed in the new branch. This flag skips the ". "is applied and committed in the new branch. This flag ".
"branch creation step and applies and commits the patch to the ". "cherry-picks the resultant commit onto the original branch and ".
"current branch.", "deletes the temporary branch.",
'conflicts' => array( 'conflicts' => array(
'update' => true, 'update' => true,
), ),
@ -219,18 +219,20 @@ EOTEXT
return true; return true;
} }
private function shouldBranch() { private function canBranch() {
// git only for now // git only for now
$repository_api = $this->getRepositoryAPI(); $repository_api = $this->getRepositoryAPI();
if (!($repository_api instanceof ArcanistGitAPI)) { if (!($repository_api instanceof ArcanistGitAPI)) {
return false; return false;
} }
return true;
}
private function shouldBranch() {
$no_branch = $this->getArgument('nobranch', false); $no_branch = $this->getArgument('nobranch', false);
if ($no_branch) { if ($no_branch) {
return false; return false;
} }
return true; return true;
} }
@ -328,10 +330,9 @@ EOTEXT
return $bookmark_name; return $bookmark_name;
} }
private function createBranch(ArcanistBundle $bundle) { private function hasBaseRevision(ArcanistBundle $bundle) {
$branch_name = $this->getBranchName($bundle); $base_revision = $bundle->getBaseRevision();
$repository_api = $this->getRepositoryAPI(); $repository_api = $this->getRepositoryAPI();
$base_revision = $bundle->getBaseRevision();
// verify the base revision is valid // verify the base revision is valid
// in a working copy that uses the git-svn bridge, the base revision might // in a working copy that uses the git-svn bridge, the base revision might
@ -343,8 +344,15 @@ EOTEXT
list($err) = $repository_api->execManualLocal( list($err) = $repository_api->execManualLocal(
'cat-file -t %s', 'cat-file -t %s',
$base_revision); $base_revision);
return !$err;
}
if ($base_revision && !$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 && $has_base_revision) {
$repository_api->execxLocal( $repository_api->execxLocal(
'checkout -b %s %s', 'checkout -b %s %s',
$branch_name, $branch_name,
@ -358,6 +366,8 @@ EOTEXT
echo phutil_console_format( echo phutil_console_format(
"Created and checked out branch %s.\n", "Created and checked out branch %s.\n",
$branch_name); $branch_name);
return $branch_name;
} }
private function createBookmark(ArcanistBundle $bundle) { private function createBookmark(ArcanistBundle $bundle) {
@ -454,15 +464,18 @@ EOTEXT
$this->updateWorkingCopy(); $this->updateWorkingCopy();
} }
if ($this->shouldBranch()) { $repository_api = $this->getRepositoryAPI();
$this->createBranch($bundle);
$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()) { if ($this->shouldBookmark()) {
$this->createBookmark($bundle); $this->createBookmark($bundle);
} }
$repository_api = $this->getRepositoryAPI();
if ($repository_api instanceof ArcanistSubversionAPI) { if ($repository_api instanceof ArcanistSubversionAPI) {
$patch_err = 0; $patch_err = 0;
@ -706,6 +719,21 @@ EOTEXT
} else { } else {
$verb = 'applied'; $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( echo phutil_console_format(
"<bg:green>** OKAY **</bg> Successfully {$verb} patch.\n"); "<bg:green>** OKAY **</bg> Successfully {$verb} patch.\n");
} else if ($repository_api instanceof ArcanistMercurialAPI) { } else if ($repository_api instanceof ArcanistMercurialAPI) {