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 @@ +