Changeset View
Changeset View
Standalone View
Standalone View
src/land/engine/ArcanistGitLandEngine.php
Show All 28 Lines | protected function pruneBranches(array $sets) { | ||||
$branch_map = $this->getBranchesForCommits( | $branch_map = $this->getBranchesForCommits( | ||||
$old_commits, | $old_commits, | ||||
$is_contains = false); | $is_contains = false); | ||||
foreach ($branch_map as $branch_name => $branch_hash) { | foreach ($branch_map as $branch_name => $branch_hash) { | ||||
$recovery_command = csprintf( | $recovery_command = csprintf( | ||||
'git checkout -b %s %s', | 'git checkout -b %s %s', | ||||
$branch_name, | $branch_name, | ||||
$this->getDisplayHash($branch_hash)); | $api->getDisplayHash($branch_hash)); | ||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('CLEANUP'), | pht('CLEANUP'), | ||||
pht('Cleaning up branch "%s". To recover, run:', $branch_name)); | pht('Cleaning up branch "%s". To recover, run:', $branch_name)); | ||||
echo tsprintf( | echo tsprintf( | ||||
"\n **$** %s\n\n", | "\n **$** %s\n\n", | ||||
$recovery_command); | $recovery_command); | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | foreach ($branch_map as $branch_name => $branch_head) { | ||||
$api->execManualLocal('reset --hard HEAD --'); | $api->execManualLocal('reset --hard HEAD --'); | ||||
$log->writeWarning( | $log->writeWarning( | ||||
pht('REBASE CONFLICT'), | pht('REBASE CONFLICT'), | ||||
pht( | pht( | ||||
'Branch "%s" does not rebase cleanly from "%s" onto '. | 'Branch "%s" does not rebase cleanly from "%s" onto '. | ||||
'"%s", skipping.', | '"%s", skipping.', | ||||
$branch_name, | $branch_name, | ||||
$this->getDisplayHash($old_commit), | $api->getDisplayHash($old_commit), | ||||
$this->getDisplayHash($rebase_target))); | $api->getDisplayHash($rebase_target))); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
private function fetchTarget(ArcanistLandTarget $target) { | private function fetchTarget(ArcanistLandTarget $target) { | ||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
$log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (!strlen($changes)) { | ||||
// TODO: We could make a more significant effort to identify the | // TODO: We could make a more significant effort to identify the | ||||
// human-readable symbol which led us to try to land this ref. | // human-readable symbol which led us to try to land this ref. | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Merging local "%s" into "%s" produces an empty diff. '. | 'Merging local "%s" into "%s" produces an empty diff. '. | ||||
'This usually means these changes have already landed.', | 'This usually means these changes have already landed.', | ||||
$this->getDisplayHash($max_hash), | $api->getDisplayHash($max_hash), | ||||
$this->getDisplayHash($into_commit))); | $api->getDisplayHash($into_commit))); | ||||
} | } | ||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('MERGING'), | pht('MERGING'), | ||||
pht( | pht( | ||||
'%s %s', | '%s %s', | ||||
$this->getDisplayHash($max_hash), | $api->getDisplayHash($max_hash), | ||||
$max_commit->getDisplaySummary())); | $max_commit->getDisplaySummary())); | ||||
$argv = array(); | $argv = array(); | ||||
$argv[] = '--no-stat'; | $argv[] = '--no-stat'; | ||||
$argv[] = '--no-commit'; | $argv[] = '--no-commit'; | ||||
// When we're merging into the empty state, Git refuses to perform the | // When we're merging into the empty state, Git refuses to perform the | ||||
// merge until we tell it explicitly that we're doing something unusual. | // merge until we tell it explicitly that we're doing something unusual. | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | try { | ||||
$is_merging = false; | $is_merging = false; | ||||
} catch (CommandException $ex) { | } catch (CommandException $ex) { | ||||
$direct_symbols = $max_commit->getDirectSymbols(); | $direct_symbols = $max_commit->getDirectSymbols(); | ||||
$indirect_symbols = $max_commit->getIndirectSymbols(); | $indirect_symbols = $max_commit->getIndirectSymbols(); | ||||
if ($direct_symbols) { | if ($direct_symbols) { | ||||
$message = pht( | $message = pht( | ||||
'Local commit "%s" (%s) does not merge cleanly into "%s". '. | 'Local commit "%s" (%s) does not merge cleanly into "%s". '. | ||||
'Merge or rebase local changes so they can merge cleanly.', | 'Merge or rebase local changes so they can merge cleanly.', | ||||
$this->getDisplayHash($max_hash), | $api->getDisplayHash($max_hash), | ||||
$this->getDisplaySymbols($direct_symbols), | $this->getDisplaySymbols($direct_symbols), | ||||
$this->getDisplayHash($into_commit)); | $api->getDisplayHash($into_commit)); | ||||
} else if ($indirect_symbols) { | } else if ($indirect_symbols) { | ||||
$message = pht( | $message = pht( | ||||
'Local commit "%s" (reachable from: %s) does not merge cleanly '. | 'Local commit "%s" (reachable from: %s) does not merge cleanly '. | ||||
'into "%s". Merge or rebase local changes so they can merge '. | 'into "%s". Merge or rebase local changes so they can merge '. | ||||
'cleanly.', | 'cleanly.', | ||||
$this->getDisplayHash($max_hash), | $api->getDisplayHash($max_hash), | ||||
$this->getDisplaySymbols($indirect_symbols), | $this->getDisplaySymbols($indirect_symbols), | ||||
$this->getDisplayHash($into_commit)); | $api->getDisplayHash($into_commit)); | ||||
} else { | } else { | ||||
$message = pht( | $message = pht( | ||||
'Local commit "%s" does not merge cleanly into "%s". Merge or '. | 'Local commit "%s" does not merge cleanly into "%s". Merge or '. | ||||
'rebase local changes so they can merge cleanly.', | 'rebase local changes so they can merge cleanly.', | ||||
$this->getDisplayHash($max_hash), | $api->getDisplayHash($max_hash), | ||||
$this->getDisplayHash($into_commit)); | $api->getDisplayHash($into_commit)); | ||||
} | } | ||||
echo tsprintf( | echo tsprintf( | ||||
"\n%!\n%W\n\n", | "\n%!\n%W\n\n", | ||||
pht('MERGE CONFLICT'), | pht('MERGE CONFLICT'), | ||||
$message); | $message); | ||||
if ($this->getHasUnpushedChanges()) { | if ($this->getHasUnpushedChanges()) { | ||||
▲ Show 20 Lines • Show All 847 Lines • ▼ Show 20 Lines | if (count($ontos) > 1) { | ||||
pht( | pht( | ||||
'Will merge into target "%s" by default, because this is the "onto" '. | 'Will merge into target "%s" by default, because this is the "onto" '. | ||||
'target.', | 'target.', | ||||
$onto)); | $onto)); | ||||
} | } | ||||
} | } | ||||
protected function selectIntoCommit() { | protected function selectIntoCommit() { | ||||
$api = $this->getRepositoryAPI(); | |||||
// Make sure that our "into" target is valid. | // Make sure that our "into" target is valid. | ||||
$log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
if ($this->getIntoEmpty()) { | if ($this->getIntoEmpty()) { | ||||
// If we're running under "--into-empty", we don't have to do anything. | // If we're running under "--into-empty", we don't have to do anything. | ||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('INTO COMMIT'), | pht('INTO COMMIT'), | ||||
pht('Preparing merge into the empty state.')); | pht('Preparing merge into the empty state.')); | ||||
return null; | return null; | ||||
} | } | ||||
if ($this->getIntoLocal()) { | if ($this->getIntoLocal()) { | ||||
// If we're running under "--into-local", just make sure that the | // If we're running under "--into-local", just make sure that the | ||||
// target identifies some actual commit. | // target identifies some actual commit. | ||||
$api = $this->getRepositoryAPI(); | |||||
$local_ref = $this->getIntoRef(); | $local_ref = $this->getIntoRef(); | ||||
list($err, $stdout) = $api->execManualLocal( | list($err, $stdout) = $api->execManualLocal( | ||||
'rev-parse --verify %s', | 'rev-parse --verify %s', | ||||
$local_ref); | $local_ref); | ||||
if ($err) { | if ($err) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Local ref "%s" does not exist.', | 'Local ref "%s" does not exist.', | ||||
$local_ref)); | $local_ref)); | ||||
} | } | ||||
$into_commit = trim($stdout); | $into_commit = trim($stdout); | ||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('INTO COMMIT'), | pht('INTO COMMIT'), | ||||
pht( | pht( | ||||
'Preparing merge into local target "%s", at commit "%s".', | 'Preparing merge into local target "%s", at commit "%s".', | ||||
$local_ref, | $local_ref, | ||||
$this->getDisplayHash($into_commit))); | $api->getDisplayHash($into_commit))); | ||||
return $into_commit; | return $into_commit; | ||||
} | } | ||||
$target = id(new ArcanistLandTarget()) | $target = id(new ArcanistLandTarget()) | ||||
->setRemote($this->getIntoRemote()) | ->setRemote($this->getIntoRemote()) | ||||
->setRef($this->getIntoRef()); | ->setRef($this->getIntoRef()); | ||||
$commit = $this->fetchTarget($target); | $commit = $this->fetchTarget($target); | ||||
if ($commit !== null) { | if ($commit !== null) { | ||||
$log->writeStatus( | $log->writeStatus( | ||||
pht('INTO COMMIT'), | pht('INTO COMMIT'), | ||||
pht( | pht( | ||||
'Preparing merge into "%s" from remote "%s", at commit "%s".', | 'Preparing merge into "%s" from remote "%s", at commit "%s".', | ||||
$target->getRef(), | $target->getRef(), | ||||
$target->getRemote(), | $target->getRemote(), | ||||
$this->getDisplayHash($commit))); | $api->getDisplayHash($commit))); | ||||
return $commit; | return $commit; | ||||
} | } | ||||
// If we have no valid target and the user passed "--into" explicitly, | // If we have no valid target and the user passed "--into" explicitly, | ||||
// treat this as an error. For example, "arc land --into Q --onto Q", | // treat this as an error. For example, "arc land --into Q --onto Q", | ||||
// where "Q" does not exist, is an error. | // where "Q" does not exist, is an error. | ||||
if ($this->getIntoArgument()) { | if ($this->getIntoArgument()) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | $log->writeStatus( | ||||
pht( | pht( | ||||
'Landing the current HEAD, "%s".', | 'Landing the current HEAD, "%s".', | ||||
$commit->getCommitHash())); | $commit->getCommitHash())); | ||||
return array($commit->getCommitHash()); | return array($commit->getCommitHash()); | ||||
} | } | ||||
private function newOntoRefArguments($into_commit) { | private function newOntoRefArguments($into_commit) { | ||||
$api = $this->getRepositoryAPI(); | |||||
$refspecs = array(); | $refspecs = array(); | ||||
foreach ($this->getOntoRefs() as $onto_ref) { | foreach ($this->getOntoRefs() as $onto_ref) { | ||||
$refspecs[] = sprintf( | $refspecs[] = sprintf( | ||||
'%s:refs/heads/%s', | '%s:refs/heads/%s', | ||||
$this->getDisplayHash($into_commit), | $api->getDisplayHash($into_commit), | ||||
$onto_ref); | $onto_ref); | ||||
} | } | ||||
return $refspecs; | return $refspecs; | ||||
} | } | ||||
private function confirmLegacyStrategyConfiguration() { | private function confirmLegacyStrategyConfiguration() { | ||||
// TODO: See T13547. Remove this check in the future. This prevents users | // TODO: See T13547. Remove this check in the future. This prevents users | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |