]> khamidou — GitHub mirrors - arcanist.git/commitdiff
In "arc patch", use "cat-file -t" instead of "rev-parse --verify" to check for commits.
authorepriestley <git@epriestley.com>
Tue, 20 Mar 2012 02:11:52 +0000 (19:11 -0700)
committerepriestley <git@epriestley.com>
Tue, 20 Mar 2012 02:11:52 +0000 (19:11 -0700)
Summary:
  - `git rev-parse --verify` "verifies" very valid-looking commit name, not just valid commit names.
  - Currently, if we can't find the base rev we'll incorrectly "verify" it and then fail on "git checkout -b <branch> <some bogus commit>".
  - Instead, use `git cat-file -t`.
  - See similar fix in D1590.

Example:

  $ git rev-parse --verify aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Test Plan: Ran "arc patch" in a mismatched local, hit "Y" to branch, got a branch off HEAD instead of an error.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1947

src/workflow/patch/ArcanistPatchWorkflow.php

index 536154d6c6d0269e2c2b6e1217cdb251bf5c474a..9df29ac0c3aca46863da2cc9842d7b12e85efcc9 100644 (file)
@@ -269,11 +269,14 @@ EOTEXT
     // verify the base revision is valid
     // in a working copy that uses the git-svn bridge, the base revision might
     // be a svn uri instead of a git ref
+
+    // NOTE: Use 'cat-file', not 'rev-parse --verify', because 'rev-parse'
+    // always "verifies" any properly-formatted commit even if it does not
+    // exist.
     list($err) = exec_manual(
-      '(cd %s; git rev-parse --verify %s)',
+      '(cd %s; git cat-file -t %s)',
       $repository_api->getPath(),
-      $base_revision
-    );
+      $base_revision);
 
     if ($base_revision && !$err) {
       execx(
@@ -289,8 +292,8 @@ EOTEXT
     }
 
     echo phutil_console_format(
-      "Created and checked out branch {$branch_name}.\n"
-    );
+      "Created and checked out branch %s.\n",
+      $branch_name);
   }
 
   private function shouldUpdateWorkingCopy() {