]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve two error handling behaviors in `arc upgrade`
authorepriestley <git@epriestley.com>
Thu, 22 Oct 2015 19:55:16 +0000 (19:55 +0000)
committerepriestley <autocommitter@example.com>
Thu, 22 Oct 2015 19:55:16 +0000 (19:55 +0000)
Summary:
Fixes T9222. Two issues here:

  - First, we currently continue on error. Throw instead. I just swapped us from "phutil_passthru()" to "execx()" since I don't think printing out the "pulling from remote..." status messages is very important, and this makes it easier to raise a useful exception.
  - Second, if you have a dirty working copy we currently may try to do some sort of silly stuff which won't work, like prompt you to amend changes. Instead, do a slightly lower-level check and just bail.

Test Plan:
  - Ran `arc upgrade` with a dirty working copy and got a tailored, useful error.
  - Ran `arc upgrade` with an artificially bad `git pull` command, got a failure with a specific error message.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9222

Differential Revision: https://secure.phabricator.com/D14317

src/workflow/ArcanistUpgradeWorkflow.php

index c9e0e8587899119a7ac3e341abf9081a4bfa12dd..50449ef75f27a2a1dab28bd6bb907435d516742f 100644 (file)
@@ -53,7 +53,27 @@ EOTEXT
 
       $this->setRepositoryAPI($repository);
 
-      $this->requireCleanWorkingCopy();
+      // 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.'));
+      }
 
       $branch_name = $repository->getBranchName();
       if ($branch_name != 'master' && $branch_name != 'stable') {
@@ -71,10 +91,13 @@ EOTEXT
       }
 
       chdir($root);
+
       try {
-        phutil_passthru('git pull --rebase');
+        execx('git pull --rebase');
       } catch (Exception $ex) {
-        phutil_passthru('git rebase --abort');
+        // If we failed, try to go back to the old state, then throw the
+        // original exception.
+        exec_manual('git rebase --abort');
         throw $ex;
       }
     }