Changeset View
Changeset View
Standalone View
Standalone View
src/land/ArcanistGitLandEngine.php
Show First 20 Lines • Show All 467 Lines • ▼ Show 20 Lines | private function reconcileLocalState() { | ||||
$api->execxLocal('checkout %s --', $local_branch); | $api->execxLocal('checkout %s --', $local_branch); | ||||
$api->execxLocal('reset --hard %s --', $this->getTargetFullRef()); | $api->execxLocal('reset --hard %s --', $this->getTargetFullRef()); | ||||
return; | return; | ||||
} | } | ||||
private function destroyLocalBranch() { | private function destroyLocalBranch() { | ||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
$source_ref = $this->getSourceRef(); | |||||
if ($this->getSourceRef() == $this->getTargetOnto()) { | if ($source_ref == $this->getTargetOnto()) { | ||||
// If we landed a branch into a branch with the same name, so don't | // If we landed a branch into a branch with the same name, so don't | ||||
// destroy it. This prevents us from cleaning up "master" if you're | // destroy it. This prevents us from cleaning up "master" if you're | ||||
// landing master into itself. | // landing master into itself. | ||||
return; | return; | ||||
} | } | ||||
// TODO: Maybe this should also recover the proper upstream? | // TODO: Maybe this should also recover the proper upstream? | ||||
// See T10321. If we were not landing a branch, don't try to clean it up. | |||||
// This happens most often when landing from a detached HEAD. | |||||
$is_branch = $this->isBranch($source_ref); | |||||
if (!$is_branch) { | |||||
echo tsprintf( | |||||
"%s\n", | |||||
pht( | |||||
'(Source "%s" is not a branch, leaving working copy as-is.)', | |||||
$source_ref)); | |||||
return; | |||||
} | |||||
$recovery_command = csprintf( | $recovery_command = csprintf( | ||||
'git checkout -b %R %R', | 'git checkout -b %R %R', | ||||
$this->getSourceRef(), | $source_ref, | ||||
$this->sourceCommit); | $this->sourceCommit); | ||||
echo tsprintf( | echo tsprintf( | ||||
"%s\n", | "%s\n", | ||||
pht('Cleaning up branch "%s"...', $this->getSourceRef())); | pht('Cleaning up branch "%s"...', $source_ref)); | ||||
echo tsprintf( | echo tsprintf( | ||||
"%s\n", | "%s\n", | ||||
pht('(Use `%s` if you want it back.)', $recovery_command)); | pht('(Use `%s` if you want it back.)', $recovery_command)); | ||||
$api->execxLocal('branch -D -- %s', $this->getSourceRef()); | $api->execxLocal('branch -D -- %s', $source_ref); | ||||
} | } | ||||
/** | /** | ||||
* Save the local working copy state so we can restore it later. | * Save the local working copy state so we can restore it later. | ||||
*/ | */ | ||||
private function saveLocalState() { | private function saveLocalState() { | ||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | echo tsprintf( | ||||
'You can go back to how things were before you ran `arc land` with '. | 'You can go back to how things were before you ran `arc land` with '. | ||||
'this command:'), | 'this command:'), | ||||
$restore_command, | $restore_command, | ||||
pht( | pht( | ||||
'Local branches have not been changed, and are still in exactly the '. | 'Local branches have not been changed, and are still in exactly the '. | ||||
'same state as before.')); | 'same state as before.')); | ||||
} | } | ||||
private function isBranch($ref) { | |||||
$api = $this->getRepositoryAPI(); | |||||
list($err) = $api->execManualLocal( | |||||
'show-ref --verify --quiet -- %R', | |||||
'refs/heads/'.$ref); | |||||
return !$err; | |||||
} | |||||
} | } |