]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use a temporary file to execute `arc patch`
authorepriestley <git@epriestley.com>
Fri, 31 May 2013 04:03:21 +0000 (21:03 -0700)
committerepriestley <git@epriestley.com>
Fri, 31 May 2013 04:03:21 +0000 (21:03 -0700)
Summary:
Piping data around on Windows doesn't work well when it contains zany characters like "null" and "newline". Fixes T3266.

Instead of piping data into `git apply`, write to a temporary file.

Test Plan:
Ran `arc patch`, got good results.

  >>> [17] <exec> $ git apply --index --reject -- '/private/var/folders/8k/c3vkmjy5335gcxdzxkhwq82w0000gn/T/7z9iea6srikoo0sc/4266-ZEyvz9'

Reviewers: btrahan, hach-que

Reviewed By: hach-que

CC: aran
Maniphest Tasks: T3266

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

src/lint/linter/ArcanistJSHintLinter.php
src/repository/api/ArcanistGitAPI.php
src/repository/api/ArcanistMercurialAPI.php
src/workflow/ArcanistPatchWorkflow.php

index 9a066dae2928e4f24558ff86462b47f7d9f5f647..849bb227e44050125c6491fbc67872737188e722 100644 (file)
@@ -101,12 +101,7 @@ final class ArcanistJSHintLinter extends ArcanistLinter {
       return $bin;
     }
 
-    // Look for globally installed JSHint
-    list($err) = (phutil_is_windows()
-      ? exec_manual('where %s', $bin)
-      : exec_manual('which %s', $bin));
-
-    if ($err) {
+    if (!Filesystem::binaryExists($bin)) {
       throw new ArcanistUsageException(
         "JSHint does not appear to be installed on this system. Install it ".
         "(e.g., with 'npm install jshint -g') or configure ".
index 17475884009343c9890af94a09513af662ba2642..da5bdcb2615f1ecd5e9e7db05967a5e8a4f4b3a5 100644 (file)
@@ -29,6 +29,27 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     return $future;
   }
 
+  public function execPassthru($pattern /* , ... */) {
+    $args = func_get_args();
+
+    static $git = null;
+    if ($git === null) {
+      if (phutil_is_windows()) {
+        // NOTE: On Windows, phutil_passthru() uses 'bypass_shell' because
+        // everything goes to hell if we don't. We must provide an absolute
+        // path to Git for this to work properly.
+        $git = Filesystem::resolveBinary('git');
+        $git = csprintf('%s', $git);
+      } else {
+        $git = 'git';
+      }
+    }
+
+    $args[0] = $git.' '.$args[0];
+
+    return call_user_func_array('phutil_passthru', $args);
+  }
+
 
   public function getSourceControlSystemName() {
     return 'git';
index 1c80dc5946e1d4ef4874bb0d3b364c72077d489e..c6e6796f9f7f0f247278a5ea8a869995781a261f 100644 (file)
@@ -45,7 +45,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
       $args[0] = 'HGPLAIN=1 hg '.$args[0];
     }
 
-    return call_user_func_array("phutil_passthru", $args);
+    return call_user_func_array('phutil_passthru', $args);
   }
 
   public function getSourceControlSystemName() {
index d353513b6156e8ec3494825386dfdcf915e25b17..36a320982e67ddb2aa8604be6c3d7319e496033f 100644 (file)
@@ -672,26 +672,24 @@ EOTEXT
 
       return $patch_err;
     } else if ($repository_api instanceof ArcanistGitAPI) {
-      $future = $repository_api->execFutureLocal(
-        'apply --index --reject');
-      $future->write($bundle->toGitPatch());
 
-      try {
-        $future->resolvex();
-      } catch (CommandException $ex) {
+      $patchfile = new TempFile();
+      Filesystem::writeFile($patchfile, $bundle->toGitPatch());
+
+      $err = $repository_api->execPassthru(
+        'apply --index --reject -- %s',
+        $patchfile);
+
+      if ($err) {
         echo phutil_console_format(
           "\n<bg:red>** Patch Failed! **</bg>\n");
-        $stderr = $ex->getStdErr();
-        if (preg_match('/already exists in working directory/', $stderr)) {
-          echo phutil_console_wrap(
-            phutil_console_format(
-              "\n<bg:yellow>** WARNING **</bg> This patch may have failed ".
-              "because it attempts to change the case of a filename (for ".
-              "instance, from 'example.c' to 'Example.c'). Git cannot apply ".
-              "patches like this on case-insensitive filesystems. You must ".
-              "apply this patch manually.\n"));
-        }
-        throw $ex;
+
+        // NOTE: Git patches may fail if they change the case of a filename
+        // (for instance, from 'example.c' to 'Example.c'). As of now, Git
+        // can not apply these patches on case-insensitive filesystems and
+        // there is no way to build a patch which works.
+
+        throw new ArcanistUsageException("Unable to apply patch!");
       }
 
       if ($this->shouldCommit()) {