2012-05-09 19:01:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upgrade arcanist itself.
|
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
final class ArcanistUpgradeWorkflow extends ArcanistWorkflow {
|
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';
|
|
|
|
}
|
|
|
|
|
2012-05-09 19:01:31 +02:00
|
|
|
public function getCommandSynopses() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**upgrade**
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
Supports: cli
|
2012-05-22 01:45:03 +02:00
|
|
|
Upgrade arcanist and libphutil to the latest versions.
|
2012-05-09 19:01:31 +02:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
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
|
|
|
|
2012-05-22 01:45:03 +02:00
|
|
|
foreach ($roots as $lib => $root) {
|
2015-05-13 10:05:15 +02:00
|
|
|
echo phutil_console_format(
|
|
|
|
"%s\n",
|
|
|
|
pht('Upgrading %s...', $lib));
|
2012-05-09 19:01:31 +02:00
|
|
|
|
2012-05-22 01:45:03 +02:00
|
|
|
$working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
|
2013-10-19 01:10:06 +02:00
|
|
|
$configuration_manager = clone $this->getConfigurationManager();
|
2013-10-19 01:19:22 +02:00
|
|
|
$configuration_manager->setWorkingCopyIdentity($working_copy);
|
2015-02-01 01:00:36 +01:00
|
|
|
$repository = ArcanistRepositoryAPI::newAPIFromConfigurationManager(
|
2013-10-19 01:10:06 +02:00
|
|
|
$configuration_manager);
|
2012-07-03 04:50:35 +02:00
|
|
|
|
2015-02-01 01:00:36 +01:00
|
|
|
if (!Filesystem::pathExists($repository->getMetadataPath())) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
pht(
|
|
|
|
"%s must be in its git working copy to be automatically upgraded. ".
|
|
|
|
"This copy of %s (in '%s') is not in a git working copy.",
|
|
|
|
$lib,
|
|
|
|
$lib,
|
|
|
|
$root));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setRepositoryAPI($repository);
|
2012-05-09 19:01:31 +02:00
|
|
|
|
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.
|
|
|
|
$uncommitted = $repository->getUncommittedStatus();
|
|
|
|
if ($uncommitted) {
|
|
|
|
$message = pht(
|
|
|
|
'You have uncommitted changes in the working copy for this '.
|
|
|
|
'library:');
|
|
|
|
|
|
|
|
$list = id(new PhutilConsoleList())
|
|
|
|
->setWrap(false)
|
|
|
|
->addItems(array_keys($uncommitted));
|
|
|
|
|
|
|
|
id(new PhutilConsoleBlock())
|
|
|
|
->addParagraph($message)
|
|
|
|
->addList($list)
|
|
|
|
->draw();
|
|
|
|
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
pht('`arc upgrade` can only upgrade clean working copies.'));
|
|
|
|
}
|
2012-05-22 01:45:03 +02:00
|
|
|
|
2015-02-01 01:00:36 +01:00
|
|
|
$branch_name = $repository->getBranchName();
|
2015-09-07 22:44:47 +02:00
|
|
|
if ($branch_name != 'master' && $branch_name != 'stable') {
|
2012-05-22 01:45:03 +02:00
|
|
|
throw new ArcanistUsageException(
|
2015-02-01 01:00:36 +01:00
|
|
|
pht(
|
2015-09-07 22:44:47 +02:00
|
|
|
"%s must be on either branch '%s' or '%s' to be automatically ".
|
|
|
|
"upgraded. ".
|
2015-02-01 01:00:36 +01:00
|
|
|
"This copy of %s (in '%s') is on branch '%s'.",
|
|
|
|
$lib,
|
|
|
|
'master',
|
2015-09-07 22:44:47 +02:00
|
|
|
'stable',
|
2015-02-01 01:00:36 +01:00
|
|
|
$lib,
|
|
|
|
$root,
|
|
|
|
$branch_name));
|
2012-05-22 01:45:03 +02:00
|
|
|
}
|
2012-05-09 19:01:31 +02:00
|
|
|
|
2012-05-22 01:45:03 +02:00
|
|
|
chdir($root);
|
2015-10-22 21:55:16 +02:00
|
|
|
|
2012-05-22 01:45:03 +02:00
|
|
|
try {
|
2015-10-22 21:55:16 +02:00
|
|
|
execx('git pull --rebase');
|
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
|
|
|
}
|
|
|
|
|
2015-02-01 01:00:36 +01:00
|
|
|
echo phutil_console_format(
|
|
|
|
"**%s** %s\n",
|
|
|
|
pht('Updated!'),
|
|
|
|
pht('Your copy of arc is now up to date.'));
|
2012-05-09 19:01:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|