2012-05-09 19:01:31 +02:00
|
|
|
<?php
|
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
final class ArcanistUpgradeWorkflow
|
|
|
|
extends ArcanistArcWorkflow {
|
2012-05-09 19:01:31 +02:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'upgrade';
|
|
|
|
}
|
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
public function getWorkflowInformation() {
|
|
|
|
$help = pht(<<<EOTEXT
|
|
|
|
Upgrade Arcanist to the latest version.
|
2012-05-09 19:01:31 +02:00
|
|
|
EOTEXT
|
2020-02-17 18:32:30 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return $this->newWorkflowInformation()
|
|
|
|
->setSynopsis(pht('Upgrade Arcanist to the latest version.'))
|
|
|
|
->addExample(pht('**upgrade**'))
|
|
|
|
->setHelp($help);
|
2012-05-09 19:01:31 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
public function getWorkflowArguments() {
|
|
|
|
return array();
|
2012-05-09 19:01:31 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
public function runWorkflow() {
|
|
|
|
$log = $this->getLogEngine();
|
|
|
|
|
2015-02-01 01:00:36 +01:00
|
|
|
$roots = array(
|
|
|
|
'arcanist' => dirname(phutil_get_library_root('arcanist')),
|
|
|
|
);
|
2012-05-09 19:01:31 +02:00
|
|
|
|
2020-02-13 15:01:26 +01:00
|
|
|
$supported_branches = array(
|
|
|
|
'master',
|
|
|
|
'stable',
|
|
|
|
);
|
|
|
|
$supported_branches = array_fuse($supported_branches);
|
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
foreach ($roots as $library => $root) {
|
|
|
|
$log->writeStatus(
|
|
|
|
pht('PREPARING'),
|
|
|
|
pht(
|
|
|
|
'Preparing to upgrade "%s"...',
|
|
|
|
$library));
|
|
|
|
|
|
|
|
$working_copy = ArcanistWorkingCopy::newFromWorkingDirectory($root);
|
2020-04-08 16:18:46 +02:00
|
|
|
|
|
|
|
$repository_api = $working_copy->getRepositoryAPI();
|
|
|
|
$is_git = ($repository_api instanceof ArcanistGitAPI);
|
2012-07-03 04:50:35 +02:00
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
if (!$is_git) {
|
|
|
|
throw new PhutilArgumentUsageException(
|
2015-02-01 01:00:36 +01:00
|
|
|
pht(
|
2020-02-17 18:32:30 +01:00
|
|
|
'The "arc upgrade" workflow uses "git pull" to upgrade '.
|
|
|
|
'Arcanist, but the "arcanist/" directory (in "%s") is not a Git '.
|
|
|
|
'working copy. You must leave "arcanist/" as a Git '.
|
|
|
|
'working copy to use "arc upgrade".',
|
2015-02-01 01:00:36 +01:00
|
|
|
$root));
|
|
|
|
}
|
|
|
|
|
2015-10-22 21:55:16 +02:00
|
|
|
// NOTE: Don't use requireCleanWorkingCopy() here because it tries to
|
|
|
|
// amend changes and generally move the workflow forward. We just want to
|
|
|
|
// abort if there are local changes and make the user sort things out.
|
2020-02-17 18:32:30 +01:00
|
|
|
$uncommitted = $repository_api->getUncommittedStatus();
|
2015-10-22 21:55:16 +02:00
|
|
|
if ($uncommitted) {
|
|
|
|
$message = pht(
|
2020-02-17 18:32:30 +01:00
|
|
|
'You have uncommitted changes in the working copy ("%s") for this '.
|
|
|
|
'library ("%s"):',
|
|
|
|
$root,
|
|
|
|
$library);
|
2015-10-22 21:55:16 +02:00
|
|
|
|
|
|
|
$list = id(new PhutilConsoleList())
|
|
|
|
->setWrap(false)
|
|
|
|
->addItems(array_keys($uncommitted));
|
|
|
|
|
|
|
|
id(new PhutilConsoleBlock())
|
|
|
|
->addParagraph($message)
|
|
|
|
->addList($list)
|
2020-02-17 18:32:30 +01:00
|
|
|
->addParagraph(
|
|
|
|
pht(
|
|
|
|
'Discard these changes before running "arc upgrade".'))
|
2015-10-22 21:55:16 +02:00
|
|
|
->draw();
|
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
throw new PhutilArgumentUsageException(
|
|
|
|
pht('"arc upgrade" can only upgrade clean working copies.'));
|
2015-10-22 21:55:16 +02:00
|
|
|
}
|
2012-05-22 01:45:03 +02:00
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
$branch_name = $repository_api->getBranchName();
|
2020-02-13 15:01:26 +01:00
|
|
|
if (!isset($supported_branches[$branch_name])) {
|
2020-02-17 18:32:30 +01:00
|
|
|
throw new PhutilArgumentUsageException(
|
2015-02-01 01:00:36 +01:00
|
|
|
pht(
|
2020-02-13 15:01:26 +01:00
|
|
|
'Library "%s" (in "%s") is on branch "%s", but this branch is '.
|
|
|
|
'not supported for automatic upgrades. Supported branches are: '.
|
|
|
|
'%s.',
|
2020-02-17 18:32:30 +01:00
|
|
|
$library,
|
2015-02-01 01:00:36 +01:00
|
|
|
$root,
|
2020-02-13 15:01:26 +01:00
|
|
|
$branch_name,
|
|
|
|
implode(', ', array_keys($supported_branches))));
|
2012-05-22 01:45:03 +02:00
|
|
|
}
|
2012-05-09 19:01:31 +02:00
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
$log->writeStatus(
|
|
|
|
pht('UPGRADING'),
|
|
|
|
pht(
|
|
|
|
'Upgrading "%s" (on branch "%s").',
|
|
|
|
$library,
|
|
|
|
$branch_name));
|
|
|
|
|
|
|
|
$command = csprintf(
|
|
|
|
'git pull --rebase origin -- %R',
|
|
|
|
$branch_name);
|
|
|
|
|
|
|
|
$future = (new PhutilExecPassthru($command))
|
|
|
|
->setCWD($root);
|
2015-10-22 21:55:16 +02:00
|
|
|
|
2012-05-22 01:45:03 +02:00
|
|
|
try {
|
2020-02-17 18:32:30 +01:00
|
|
|
$this->newCommand($future)
|
|
|
|
->execute();
|
2012-05-22 01:45:03 +02:00
|
|
|
} catch (Exception $ex) {
|
2015-10-22 21:55:16 +02:00
|
|
|
// If we failed, try to go back to the old state, then throw the
|
|
|
|
// original exception.
|
|
|
|
exec_manual('git rebase --abort');
|
2012-05-22 01:45:03 +02:00
|
|
|
throw $ex;
|
|
|
|
}
|
2012-05-09 19:01:31 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 18:32:30 +01:00
|
|
|
$log->writeSuccess(
|
|
|
|
pht('UPGRADED'),
|
|
|
|
pht('Your copy of Arcanist is now up to date.'));
|
|
|
|
|
2012-05-09 19:01:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|