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

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
This commit is contained in:
epriestley 2012-12-21 14:18:07 -08:00
parent f830b3bf3f
commit cffe1942ec

View file

@ -135,7 +135,13 @@ EOTEXT
public function run() { public function run() {
$this->readArguments(); $this->readArguments();
$this->validate(); $this->validate();
$this->pullFromRemote();
try {
$this->pullFromRemote();
} catch (Exception $ex) {
$this->restoreBranch();
throw $ex;
}
$this->checkoutBranch(); $this->checkoutBranch();
$this->findRevision(); $this->findRevision();
@ -148,6 +154,7 @@ EOTEXT
} }
$this->push(); $this->push();
if (!$this->keepBranch) { if (!$this->keepBranch) {
$this->cleanupBranch(); $this->cleanupBranch();
} }
@ -155,13 +162,7 @@ EOTEXT
// If we were on some branch A and the user ran "arc land B", // If we were on some branch A and the user ran "arc land B",
// switch back to A. // switch back to A.
if ($this->oldBranch != $this->branch && $this->oldBranch != $this->onto) { if ($this->oldBranch != $this->branch && $this->oldBranch != $this->onto) {
$repository_api = $this->getRepositoryAPI(); $this->restoreBranch();
$repository_api->execxLocal(
'checkout %s',
$this->oldBranch);
echo phutil_console_format(
"Switched back to branch **%s**.\n",
$this->oldBranch);
} }
echo "Done.\n"; echo "Done.\n";
@ -698,8 +699,7 @@ EOTEXT
$repository_api->execxLocal( $repository_api->execxLocal(
'commit -F %s', 'commit -F %s',
$this->messageFile); $this->messageFile);
} } else if ($this->isHg) {
else if ($this->isHg) {
// hg rebase produces a commit earlier as part of rebase // hg rebase produces a commit earlier as part of rebase
if (!$this->useSquash) { if (!$this->useSquash) {
$repository_api->execxLocal( $repository_api->execxLocal(
@ -719,22 +719,25 @@ EOTEXT
if ($this->isGitSvn) { if ($this->isGitSvn) {
$err = phutil_passthru('git svn dcommit'); $err = phutil_passthru('git svn dcommit');
$cmd = "git svn dcommit";
} else if ($this->isGit) { } else if ($this->isGit) {
$err = phutil_passthru( $err = phutil_passthru(
'git push %s %s', 'git push %s %s',
$this->remote, $this->remote,
$this->onto); $this->onto);
} $cmd = "git push";
else if ($this->isHg) { } else if ($this->isHg) {
$err = $repository_api->execPassthru( $err = $repository_api->execPassthru(
'push --new-branch -r %s %s', 'push --new-branch -r %s %s',
$this->onto, $this->onto,
$this->remote); $this->remote);
$cmd = "hg push";
} }
if ($err) { if ($err) {
$repo_command = $repository_api->getSourceControlSystemName(); echo phutil_console_format("<bg:red>** PUSH FAILED! **</bg>\n");
throw new ArcanistUsageException("'{$repo_command} push' failed."); throw new ArcanistUsageException(
"'{$cmd}' failed! Fix the error and push this change manually.");
} }
$mark_workflow = $this->buildChildWorkflow( $mark_workflow = $this->buildChildWorkflow(
@ -792,8 +795,7 @@ EOTEXT
$this->remote, $this->remote,
$this->branch); $this->branch);
} }
} } else if ($this->isHg) {
else if ($this->isHg) {
// named branches were closed as part of the earlier commit // named branches were closed as part of the earlier commit
// so only worry about bookmarks // so only worry about bookmarks
if ($repository_api->isBookmark($this->branch)) { if ($repository_api->isBookmark($this->branch)) {
@ -814,8 +816,7 @@ EOTEXT
$repository_api = $this->getRepositoryAPI(); $repository_api = $this->getRepositoryAPI();
if ($this->isGit) { if ($this->isGit) {
$branch = $repository_api->getBranchName(); $branch = $repository_api->getBranchName();
} } else if ($this->isHg) {
else if ($this->isHg) {
$branch = $repository_api->getActiveBookmark(); $branch = $repository_api->getActiveBookmark();
if (!$branch) { if (!$branch) {
$branch = $repository_api->getBranchName(); $branch = $repository_api->getBranchName();
@ -824,4 +825,20 @@ EOTEXT
return $branch; 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);
}
} }