]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Don't parse separator tabs as part of the filename in Git diffs which affect files...
authorepriestley <git@epriestley.com>
Thu, 14 Aug 2014 19:13:02 +0000 (12:13 -0700)
committerepriestley <git@epriestley.com>
Thu, 14 Aug 2014 19:13:02 +0000 (12:13 -0700)
Summary:
Fixes T5870. When a filename contains spaces, Git will add a "\t" at the end of the "---" and "+++" lines. We currently consume this and think we're reading a file called "blah blah\t".

Instead, parse it out as not part of the filename.

Test Plan: Added failing unit test and made it pass.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5870

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

src/parser/ArcanistDiffParser.php
src/parser/__tests__/ArcanistDiffParserTestCase.php
src/parser/__tests__/diff/git-remove-spaces.gitdiff [new file with mode: 0644]

index 50d9c3bd7f75fff9b1fe6c5deb16e5128f843a93..658601c3bd7e16d2ab5e6d9107305dd1dbc18031 100644 (file)
@@ -830,6 +830,10 @@ final class ArcanistDiffParser {
       $remainder = '\t.*';
     } else if ($this->isRCS) {
       $remainder = '\s.*';
+    } else if ($this->getIsGit()) {
+      // When filenames contain spaces, Git terminates this line with a tab.
+      // Normally, the tab is not present. If there's a tab, ignore it.
+      $remainder = '(?:\t.*)?';
     }
 
     $ok = preg_match(
index 8e547a6edb10c634c76dae8ee8c3d8b893a009bf..378013150d5e4a343813823e03b11a35ae98955c 100644 (file)
@@ -595,6 +595,12 @@ EOTEXT
         $hunks = $change->getHunks();
         $this->assertEqual(1, count($hunks));
         break;
+      case 'git-remove-spaces.gitdiff':
+        $this->assertEqual(1, count($changes));
+
+        $change = array_shift($changes);
+        $this->assertEqual('file with spaces.txt', $change->getOldPath());
+        break;
       default:
         throw new Exception("No test block for diff file {$diff_file}.");
         break;
diff --git a/src/parser/__tests__/diff/git-remove-spaces.gitdiff b/src/parser/__tests__/diff/git-remove-spaces.gitdiff
new file mode 100644 (file)
index 0000000..a0723ab
--- /dev/null
@@ -0,0 +1,11 @@
+diff --git a/file with spaces.txt b/file with spaces.txt
+deleted file mode 100644
+index ae9854d..0000000
+--- a/file with spaces.txt     
++++ /dev/null
+@@ -1,5 +0,0 @@
+-duck
+-duck
+-duck
+-duck
+-goose