Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistLandWorkflow.php
Show First 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | public function run() { | ||||
$this->readArguments(); | $this->readArguments(); | ||||
$engine = null; | $engine = null; | ||||
if ($this->isGit && !$this->isGitSvn) { | if ($this->isGit && !$this->isGitSvn) { | ||||
$engine = new ArcanistGitLandEngine(); | $engine = new ArcanistGitLandEngine(); | ||||
} | } | ||||
if ($engine) { | if ($engine) { | ||||
$this->readEngineArguments(); | |||||
$this->requireCleanWorkingCopy(); | |||||
$should_hold = $this->getArgument('hold'); | $should_hold = $this->getArgument('hold'); | ||||
$remote_arg = $this->getArgument('remote'); | |||||
$onto_arg = $this->getArgument('onto'); | |||||
$engine | $engine | ||||
->setWorkflow($this) | ->setWorkflow($this) | ||||
->setRepositoryAPI($this->getRepositoryAPI()) | ->setRepositoryAPI($this->getRepositoryAPI()) | ||||
->setSourceRef($this->branch) | ->setSourceRef($this->branch) | ||||
->setTargetRemote($this->remote) | |||||
->setTargetOnto($this->onto) | |||||
->setShouldHold($should_hold) | ->setShouldHold($should_hold) | ||||
->setShouldKeep($this->keepBranch) | ->setShouldKeep($this->keepBranch) | ||||
->setShouldSquash($this->useSquash) | ->setShouldSquash($this->useSquash) | ||||
->setShouldPreview($this->preview) | ->setShouldPreview($this->preview) | ||||
->setRemoteArgument($remote_arg) | |||||
->setOntoArgument($onto_arg) | |||||
->setBuildMessageCallback(array($this, 'buildEngineMessage')); | ->setBuildMessageCallback(array($this, 'buildEngineMessage')); | ||||
// The goal here is to raise errors with flags early (which is cheap), | |||||
// before we test if the working copy is clean (which can be slow). This | |||||
// could probably be structured more cleanly. | |||||
$engine->parseArguments(); | |||||
$this->requireCleanWorkingCopy(); | |||||
$engine->execute(); | $engine->execute(); | ||||
if (!$should_hold && !$this->preview) { | if (!$should_hold && !$this->preview) { | ||||
$this->didPush(); | $this->didPush(); | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | private function getGitSvnTrunk() { | ||||
if (substr($refspec, 0, strlen($prefix)) !== $prefix) { | if (substr($refspec, 0, strlen($prefix)) !== $prefix) { | ||||
return 'trunk'; | return 'trunk'; | ||||
} | } | ||||
$refspec = substr($refspec, strlen($prefix)); | $refspec = substr($refspec, strlen($prefix)); | ||||
return $refspec; | return $refspec; | ||||
} | } | ||||
private function readEngineArguments() { | |||||
// NOTE: This is hard-coded for Git right now. | |||||
// TODO: Clean this up and move it into LandEngines. | |||||
$onto = $this->getEngineOnto(); | |||||
$remote = $this->getEngineRemote(); | |||||
// This just overwrites work we did earlier, but it has to be up in this | |||||
// class for now because other parts of the workflow still depend on it. | |||||
$this->onto = $onto; | |||||
$this->remote = $remote; | |||||
$this->ontoRemoteBranch = $this->remote.'/'.$onto; | |||||
} | |||||
private function getEngineOnto() { | |||||
$onto = $this->getArgument('onto'); | |||||
if ($onto !== null) { | |||||
$this->writeInfo( | |||||
pht('TARGET'), | |||||
pht( | |||||
'Landing onto "%s", selected by the --onto flag.', | |||||
$onto)); | |||||
return $onto; | |||||
} | |||||
$api = $this->getRepositoryAPI(); | |||||
$path = $api->getPathToUpstream($this->branch); | |||||
if ($path->getLength()) { | |||||
$cycle = $path->getCycle(); | |||||
if ($cycle) { | |||||
$this->writeWarn( | |||||
pht('LOCAL CYCLE'), | |||||
pht( | |||||
'Local branch tracks an upstream, but following it leads to a '. | |||||
'local cycle; ignoring branch upstream.')); | |||||
echo tsprintf( | |||||
"\n %s\n\n", | |||||
implode(' -> ', $cycle)); | |||||
} else { | |||||
if ($path->isConnectedToRemote()) { | |||||
$onto = $path->getRemoteBranchName(); | |||||
$this->writeInfo( | |||||
pht('TARGET'), | |||||
pht( | |||||
'Landing onto "%s", selected by following tracking branches '. | |||||
'upstream to the closest remote.', | |||||
$onto)); | |||||
return $onto; | |||||
} else { | |||||
$this->writeInfo( | |||||
pht('NO PATH TO UPSTREAM'), | |||||
pht( | |||||
'Local branch tracks an upstream, but there is no path '. | |||||
'to a remote; ignoring branch upstream.')); | |||||
} | |||||
} | |||||
} | |||||
$config_key = 'arc.land.onto.default'; | |||||
$onto = $this->getConfigFromAnySource($config_key); | |||||
if ($onto !== null) { | |||||
$this->writeInfo( | |||||
pht('TARGET'), | |||||
pht( | |||||
'Landing onto "%s", selected by "%s" configuration.', | |||||
$onto, | |||||
$config_key)); | |||||
return $onto; | |||||
} | |||||
$onto = 'master'; | |||||
$this->writeInfo( | |||||
pht('TARGET'), | |||||
pht( | |||||
'Landing onto "%s", the default target under git.', | |||||
$onto)); | |||||
return $onto; | |||||
} | |||||
private function getEngineRemote() { | |||||
$remote = $this->getArgument('remote'); | |||||
if ($remote !== null) { | |||||
$this->writeInfo( | |||||
pht('REMOTE'), | |||||
pht( | |||||
'Using remote "%s", selected by the --remote flag.', | |||||
$remote)); | |||||
return $remote; | |||||
} | |||||
$api = $this->getRepositoryAPI(); | |||||
$path = $api->getPathToUpstream($this->branch); | |||||
$remote = $path->getRemoteRemoteName(); | |||||
if ($remote !== null) { | |||||
$this->writeInfo( | |||||
pht('REMOTE'), | |||||
pht( | |||||
'Using remote "%s", selected by following tracking branches '. | |||||
'upstream to the closest remote.', | |||||
$remote)); | |||||
return $remote; | |||||
} | |||||
$remote = 'origin'; | |||||
$this->writeInfo( | |||||
pht('REMOTE'), | |||||
pht( | |||||
'Using remote "%s", the default remote under git.', | |||||
$remote)); | |||||
return $remote; | |||||
} | |||||
private function readArguments() { | private function readArguments() { | ||||
$repository_api = $this->getRepositoryAPI(); | $repository_api = $this->getRepositoryAPI(); | ||||
$this->isGit = $repository_api instanceof ArcanistGitAPI; | $this->isGit = $repository_api instanceof ArcanistGitAPI; | ||||
$this->isHg = $repository_api instanceof ArcanistMercurialAPI; | $this->isHg = $repository_api instanceof ArcanistMercurialAPI; | ||||
if ($this->isGit) { | if ($this->isGit) { | ||||
$repository = $this->loadProjectRepository(); | $repository = $this->loadProjectRepository(); | ||||
$this->isGitSvn = (idx($repository, 'vcs') == 'svn'); | $this->isGitSvn = (idx($repository, 'vcs') == 'svn'); | ||||
▲ Show 20 Lines • Show All 1,244 Lines • Show Last 20 Lines |