From 129d51fa0936c9bae48fadf3a3f39e26d69d24da Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 18 May 2017 12:09:44 -0400 Subject: [PATCH] If the base commit for `arc patch` does not exist locally, try to fetch it Summary: If the commit does not exist locally, aborting still leaves the user checked out on the branch. In nearly all cases, all that is necessary is a fetch -- but the branch must also be cleaned up. This leads to the pattern of: ``` arc patch D12345 [...base commit does not exist...] ^C git checkout master git branch -D arcpatch-D12345 git fetch arc patch D12345 ``` Solve this common problem by simply trying to fetch once if the commit does not exist locally. Test Plan: Ran `arc patch` on a recent diff. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D17949 --- src/workflow/ArcanistPatchWorkflow.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/workflow/ArcanistPatchWorkflow.php b/src/workflow/ArcanistPatchWorkflow.php index c1a8f878..227b020f 100644 --- a/src/workflow/ArcanistPatchWorkflow.php +++ b/src/workflow/ArcanistPatchWorkflow.php @@ -430,6 +430,18 @@ EOTEXT $repository_api = $this->getRepositoryAPI(); $has_base_revision = $repository_api->hasLocalCommit( $bundle->getBaseRevision()); + if (!$has_base_revision) { + if ($repository_api instanceof ArcanistGitAPI) { + echo phutil_console_format( + "** %s ** %s\n", + pht('INFO'), + pht('Base commit is not in local repository; trying to fetch.')); + $repository_api->execManualLocal('fetch --quiet --all'); + $has_base_revision = $repository_api->hasLocalCommit( + $bundle->getBaseRevision()); + } + } + if ($this->canBranch() && ($this->shouldBranch() || ($this->shouldCommit() && $has_base_revision))) {