]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Provide a better error message for 'arc patch' when patches fail.
authorepriestley <epriestley@javelinjs.com>
Thu, 13 Jan 2011 21:21:33 +0000 (13:21 -0800)
committerepriestley <epriestley@javelinjs.com>
Thu, 13 Jan 2011 21:40:09 +0000 (13:40 -0800)
Summary:
Be more clear about what happened.

Test Plan:
ran 'arc patch' on good/bad patches

Differential Revision: 201085
Reviewed By: adonohue
Reviewers: adonohue
CC: adonohue
Revert Plan:
OK

src/workflow/diff/ArcanistDiffWorkflow.php
src/workflow/patch/ArcanistPatchWorkflow.php

index 6e928ea44a6f9fde019e9cc8aab37c13e034b46b..7135c255bd4c7bf72a7f1896de9728288d6ce2d6 100644 (file)
@@ -20,7 +20,7 @@ class ArcanistDiffWorkflow extends ArcanistBaseWorkflow {
 
   private $hasWarnedExternals = false;
   private $unresolvedLint;
-  private $unresolvedUnit;
+  private $unresolvedTests;
 
   public function getCommandHelp() {
     return phutil_console_format(<<<EOTEXT
index 22028038b0ea298d32a46ebff09cbbd699a28dce..11c63dad061be422a5e8a23a5852ba44a68f9d46 100644 (file)
@@ -162,6 +162,8 @@ EOTEXT
 
     $repository_api = $this->getRepositoryAPI();
     if ($repository_api instanceof ArcanistSubversionAPI) {
+      $patch_err = 0;
+
       $copies = array();
       $deletes = array();
       $patches = array();
@@ -248,11 +250,16 @@ EOTEXT
       foreach ($patches as $path => $patch) {
         $tmp = new TempFile();
         Filesystem::writeFile($tmp, $patch);
+        $err = null;
         passthru(
           csprintf(
             '(cd %s; patch -p0 < %s)',
             $repository_api->getPath(),
-            $tmp));
+            $tmp),
+          $err);
+        if ($err) {
+          $patch_err = max($patch_err, $err);
+        }
       }
 
       foreach ($adds as $add) {
@@ -286,13 +293,32 @@ EOTEXT
         }
       }
 
-      echo "Applied patch.\n";
+      if ($patch_err == 0) {
+        echo phutil_console_format(
+          "<bg:green>** OKAY **</bg> Successfully applied patch to the ".
+          "working copy.\n");
+      } else {
+        echo phutil_console_format(
+          "\n\n<bg:yellow>** WARNING **</bg> Some hunks could not be applied ".
+          "cleanly by the unix 'patch' utility. Your working copy may be ".
+          "different from the revision's base, or you may be in the wrong ".
+          "subdirectory. You can export the raw patch file using ".
+          "'arc export --unified', and then try to apply it by fiddling with ".
+          "options to 'patch' (particularly, -p), or manually. The output ".
+          "above, from 'patch', may be helpful in figuring out what went ".
+          "wrong.\n");
+      }
+
+      return $patch_err;
     } else {
       $future = new ExecFuture(
         '(cd %s; git apply --index)',
         $repository_api->getPath());
       $future->write($bundle->toGitPatch());
       $future->resolvex();
+
+      echo phutil_console_format(
+        "<bg:green>** OKAY **</bg> Successfully applied patch.\n");
     }
 
     return 0;