]> khamidou — GitHub mirrors - arcanist.git/commitdiff
"arc upgrade", to automatically upgrade arc (client changes)
authorepriestley <git@epriestley.com>
Wed, 9 May 2012 17:01:31 +0000 (10:01 -0700)
committerepriestley <git@epriestley.com>
Wed, 9 May 2012 17:01:31 +0000 (10:01 -0700)
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
src/workflow/base/ArcanistBaseWorkflow.php
src/workflow/upgrade/ArcanistUpgradeWorkflow.php [new file with mode: 0644]
src/workflow/upgrade/__init__.php [new file with mode: 0644]

index c78e02894cf7ba4f9e38ab843450e8bbb15235f8..d5815b130d4a651eb2cdb781e6e9351e02a8db75 100644 (file)
@@ -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',
index cfb5e204ecc5668578be2bfe5e375246f6815843..e7cb4560162c2627067068b8901d62ef38f2ceed 100644 (file)
@@ -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 (file)
index 0000000..58b5135
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+
+/*
+ * Copyright 2012 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Upgrade arcanist itself.
+ *
+ * @group workflow
+ */
+final class ArcanistUpgradeWorkflow extends ArcanistBaseWorkflow {
+
+  public function getCommandSynopses() {
+    return phutil_console_format(<<<EOTEXT
+      **upgrade**
+EOTEXT
+      );
+  }
+
+  public function getCommandHelp() {
+    return phutil_console_format(<<<EOTEXT
+          Supports: cli
+          Upgrade arc to the latest version.
+EOTEXT
+      );
+  }
+
+  public function getArguments() {
+    return array();
+  }
+
+  public function run() {
+    echo "Upgrading arc...\n";
+    $root = dirname(phutil_get_library_root('arcanist'));
+
+    if (!Filesystem::pathExists($root.'/.git')) {
+      throw new ArcanistUsageException(
+        "arc must be in its git working copy to be automatically upgraded. ".
+        "This copy of arc (in '{$root}') is not in a git working copy.");
+    }
+
+    $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
+
+    $repository_api = ArcanistRepositoryAPI::newAPIFromWorkingCopyIdentity(
+      $working_copy);
+    $this->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 (file)
index 0000000..8496a44
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+/**
+ * This file is automatically generated. Lint this module to rebuild it.
+ * @generated
+ */
+
+
+
+phutil_require_module('arcanist', 'exception/usage');
+phutil_require_module('arcanist', 'repository/api/base');
+phutil_require_module('arcanist', 'workflow/base');
+phutil_require_module('arcanist', 'workingcopyidentity');
+
+phutil_require_module('phutil', 'console');
+phutil_require_module('phutil', 'filesystem');
+phutil_require_module('phutil', 'future/exec');
+phutil_require_module('phutil', 'moduleutils');
+
+
+phutil_require_source('ArcanistUpgradeWorkflow.php');