From: epriestley Date: Fri, 21 Dec 2012 22:18:07 +0000 (-0800) Subject: Improve `arc land` recovery from issues with the remote. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=cffe1942ecd4d73cc7a287d30ffbdefe3e836a36;p=arcanist.git Improve `arc land` recovery from issues with the remote. Summary: Fixes T2138. - When a pull fails, restore the original branch. - When a push fails, complain about it really loudly. NOTE: No test plan for push yet since I'm not sure this is the right remedy, see T2138 for discsusion. Test Plan: - Tested pull by changing "git pull" to "git xxpull" and running "arc land". Saw the pull fail and my original branch restored. Reviewers: vrana, aran Reviewed By: vrana Maniphest Tasks: T2138 Differential Revision: https://secure.phabricator.com/D4265 --- diff --git a/src/workflow/ArcanistLandWorkflow.php b/src/workflow/ArcanistLandWorkflow.php index 55c282a6..9525079a 100644 --- a/src/workflow/ArcanistLandWorkflow.php +++ b/src/workflow/ArcanistLandWorkflow.php @@ -135,7 +135,13 @@ EOTEXT public function run() { $this->readArguments(); $this->validate(); - $this->pullFromRemote(); + + try { + $this->pullFromRemote(); + } catch (Exception $ex) { + $this->restoreBranch(); + throw $ex; + } $this->checkoutBranch(); $this->findRevision(); @@ -148,6 +154,7 @@ EOTEXT } $this->push(); + if (!$this->keepBranch) { $this->cleanupBranch(); } @@ -155,13 +162,7 @@ EOTEXT // If we were on some branch A and the user ran "arc land B", // switch back to A. if ($this->oldBranch != $this->branch && $this->oldBranch != $this->onto) { - $repository_api = $this->getRepositoryAPI(); - $repository_api->execxLocal( - 'checkout %s', - $this->oldBranch); - echo phutil_console_format( - "Switched back to branch **%s**.\n", - $this->oldBranch); + $this->restoreBranch(); } echo "Done.\n"; @@ -698,8 +699,7 @@ EOTEXT $repository_api->execxLocal( 'commit -F %s', $this->messageFile); - } - else if ($this->isHg) { + } else if ($this->isHg) { // hg rebase produces a commit earlier as part of rebase if (!$this->useSquash) { $repository_api->execxLocal( @@ -719,22 +719,25 @@ EOTEXT if ($this->isGitSvn) { $err = phutil_passthru('git svn dcommit'); + $cmd = "git svn dcommit"; } else if ($this->isGit) { $err = phutil_passthru( 'git push %s %s', $this->remote, $this->onto); - } - else if ($this->isHg) { + $cmd = "git push"; + } else if ($this->isHg) { $err = $repository_api->execPassthru( 'push --new-branch -r %s %s', $this->onto, $this->remote); + $cmd = "hg push"; } if ($err) { - $repo_command = $repository_api->getSourceControlSystemName(); - throw new ArcanistUsageException("'{$repo_command} push' failed."); + echo phutil_console_format("** PUSH FAILED! **\n"); + throw new ArcanistUsageException( + "'{$cmd}' failed! Fix the error and push this change manually."); } $mark_workflow = $this->buildChildWorkflow( @@ -792,8 +795,7 @@ EOTEXT $this->remote, $this->branch); } - } - else if ($this->isHg) { + } else if ($this->isHg) { // named branches were closed as part of the earlier commit // so only worry about bookmarks if ($repository_api->isBookmark($this->branch)) { @@ -814,8 +816,7 @@ EOTEXT $repository_api = $this->getRepositoryAPI(); if ($this->isGit) { $branch = $repository_api->getBranchName(); - } - else if ($this->isHg) { + } else if ($this->isHg) { $branch = $repository_api->getActiveBookmark(); if (!$branch) { $branch = $repository_api->getBranchName(); @@ -824,4 +825,20 @@ EOTEXT return $branch; } + + + /** + * Restore the original branch, e.g. after a successful land or a failed + * pull. + */ + private function restoreBranch() { + $repository_api = $this->getRepositoryAPI(); + $repository_api->execxLocal( + 'checkout %s', + $this->oldBranch); + echo phutil_console_format( + "Switched back to branch **%s**.\n", + $this->oldBranch); + } + }