From 19aa759f39e8db1cb4ccd157f0f0d634adb6ff1d Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 9 May 2012 10:01:31 -0700 Subject: [PATCH] "arc upgrade", to automatically upgrade arc (client changes) Summary: - Try to limit the pain of //future// version bumps by making arc self-updating. - When the server needs a newer version, prompt the user to update. - (We need them to reissue their command because we may already have loaded classes which have changed in the update.) - Make the message sound exciting! Test Plan: Artifically bumped server forward, ran "arc list", got to upgrade! Reviewers: Makinde, nh, jungejason, btrahan Reviewed By: nh CC: aran Differential Revision: https://secure.phabricator.com/D2435 --- src/__phutil_library_map__.php | 2 + src/workflow/base/ArcanistBaseWorkflow.php | 24 +++++ .../upgrade/ArcanistUpgradeWorkflow.php | 87 +++++++++++++++++++ src/workflow/upgrade/__init__.php | 20 +++++ 4 files changed, 133 insertions(+) create mode 100644 src/workflow/upgrade/ArcanistUpgradeWorkflow.php create mode 100644 src/workflow/upgrade/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c78e0289..d5815b13 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -102,6 +102,7 @@ phutil_register_library_map(array( 'ArcanistUncommittedChangesException' => 'exception/usage/uncommittedchanges', 'ArcanistUnitTestResult' => 'unit/result', 'ArcanistUnitWorkflow' => 'workflow/unit', + 'ArcanistUpgradeWorkflow' => 'workflow/upgrade', 'ArcanistUploadWorkflow' => 'workflow/upload', 'ArcanistUsageException' => 'exception/usage', 'ArcanistUserAbortException' => 'exception/usage/userabort', @@ -185,6 +186,7 @@ phutil_register_library_map(array( 'ArcanistTextLinterTestCase' => 'ArcanistLinterTestCase', 'ArcanistUncommittedChangesException' => 'ArcanistUsageException', 'ArcanistUnitWorkflow' => 'ArcanistBaseWorkflow', + 'ArcanistUpgradeWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistUploadWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistUserAbortException' => 'ArcanistUsageException', 'ArcanistWhichWorkflow' => 'ArcanistBaseWorkflow', diff --git a/src/workflow/base/ArcanistBaseWorkflow.php b/src/workflow/base/ArcanistBaseWorkflow.php index cfb5e204..e7cb4560 100644 --- a/src/workflow/base/ArcanistBaseWorkflow.php +++ b/src/workflow/base/ArcanistBaseWorkflow.php @@ -256,6 +256,30 @@ abstract class ArcanistBaseWorkflow { "\n". $ex->getMessage(); throw new ArcanistUsageException($message); + } else if ($ex->getErrorCode() == 'NEW-ARC-VERSION') { + + // Cleverly disguise this as being AWESOME!!! + + echo phutil_console_format("**New Version Available!**\n\n"); + echo phutil_console_wrap($ex->getMessage()); + echo "\n\n"; + echo "In most cases, arc can be upgraded automatically.\n"; + + $ok = phutil_console_confirm( + "Upgrade arc now?", + $default_no = false); + if (!$ok) { + throw $ex; + } + + $root = dirname(phutil_get_library_root('arcanist')); + + chdir($root); + $err = phutil_passthru('%s upgrade', $root.'/bin/arc'); + if (!$err) { + echo "\nTry running your arc command again.\n"; + } + exit(1); } else { throw $ex; } diff --git a/src/workflow/upgrade/ArcanistUpgradeWorkflow.php b/src/workflow/upgrade/ArcanistUpgradeWorkflow.php new file mode 100644 index 00000000..58b51353 --- /dev/null +++ b/src/workflow/upgrade/ArcanistUpgradeWorkflow.php @@ -0,0 +1,87 @@ +setRepositoryAPI($repository_api); + + // Require no local changes. + $this->requireCleanWorkingCopy(); + + // Require arc be on master. + $branch_name = $repository_api->getBranchName(); + if ($branch_name != 'master') { + throw new ArcanistUsageException( + "arc must be on branch 'master' to be automatically upgraded. ". + "This copy of arc (in '{$root}') is on branch '{$branch_name}'."); + } + + chdir($root); + try { + phutil_passthru('git pull --rebase'); + } catch (Exception $ex) { + phutil_passthru('git rebase --abort'); + throw $ex; + } + + echo phutil_console_wrap( + phutil_console_format( + "**Updated!** Your copy of arc is now up to date.\n")); + + return 0; + } + +} diff --git a/src/workflow/upgrade/__init__.php b/src/workflow/upgrade/__init__.php new file mode 100644 index 00000000..8496a44f --- /dev/null +++ b/src/workflow/upgrade/__init__.php @@ -0,0 +1,20 @@ +