]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix an escaping issue with "svn commit"
authorepriestley <git@epriestley.com>
Mon, 28 Jan 2013 22:11:31 +0000 (14:11 -0800)
committerepriestley <git@epriestley.com>
Mon, 28 Jan 2013 22:11:31 +0000 (14:11 -0800)
Summary: Fixes T2438. We currently escape everything with '@', but SVN rejects that for '.'

Test Plan:
Unit tests. Performed this commit:

  $ svn st
   M      .
  A       x@123
  $ arc commit --conduit-uri=http://local.aphront.com:8080/ --revision 53

      Revision 'D53: asdf' has not been accepted. Commit this revision anyway?
      [y/N] y

  Committing 'D53: asdf'...
  Sending        .
  Adding         x@123
  Transmitting file data .
  Committed revision 37.
  Done.

I grepped for more '@' adding but couldn't find any. It's a bit tricky to grep for though, so it's possible I missed some.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran, mbishopim3
Maniphest Tasks: T2438

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

src/__phutil_library_map__.php
src/repository/api/ArcanistSubversionAPI.php
src/repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php [new file with mode: 0644]
src/workflow/ArcanistCommitWorkflow.php

index 03370337f522261d0e4d454a387db84aa5c0e0cd..b71f0bb185a7831735b957f5020b990937ff2b58 100644 (file)
@@ -109,6 +109,7 @@ phutil_register_library_map(array(
     'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
     'ArcanistPyLintLinter' => 'lint/linter/ArcanistPyLintLinter.php',
     'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
+    'ArcanistRepositoryAPIMiscTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php',
     'ArcanistRepositoryAPIStateTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIStateTestCase.php',
     'ArcanistRubyLinter' => 'lint/linter/ArcanistRubyLinter.php',
     'ArcanistRubyLinterTestCase' => 'lint/linter/__tests__/ArcanistRubyLinterTestCase.php',
@@ -232,6 +233,7 @@ phutil_register_library_map(array(
     'ArcanistPhutilTestTerminatedException' => 'Exception',
     'ArcanistPyFlakesLinter' => 'ArcanistLinter',
     'ArcanistPyLintLinter' => 'ArcanistLinter',
+    'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
     'ArcanistRepositoryAPIStateTestCase' => 'ArcanistTestCase',
     'ArcanistRubyLinter' => 'ArcanistLinter',
     'ArcanistRubyLinterTestCase' => 'ArcanistArcanistLinterTestCase',
index edb71a1b89c8873c20f390ab515ead0b476274c1..672cd13ea7a4f3ebdb90d6ce07f786a8da3a013e 100644 (file)
@@ -637,4 +637,19 @@ EODIFF;
     $this->execxLocal('up');
   }
 
+  public static function escapeFileNamesForSVN(array $files) {
+    // SVN interprets "x@1" as meaning "file x at revision 1", which is not
+    // intended for files named "sprite@2x.png" or similar. For files with an
+    // "@" in their names, escape them by adding "@" at the end, which SVN
+    // interprets as "at the working copy revision". There is a special case
+    // where ".@" means "fail with an error" instead of ". at the working copy
+    // revision", so avoid escaping "." into ".@".
+    foreach ($files as $k => $file) {
+      if (strpos($file, '@') !== false) {
+        $files[$k] = $file.'@';
+      }
+    }
+    return $files;
+  }
+
 }
diff --git a/src/repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php b/src/repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php
new file mode 100644 (file)
index 0000000..957a42b
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+final class ArcanistRepositoryAPIMiscTestCase extends ArcanistTestCase {
+
+  public function testSVNFileEscapes() {
+    $input = array(
+      '.',
+      'x',
+      'x@2x.png',
+    );
+
+    $expect = array(
+      '.',
+      'x',
+      'x@2x.png@',
+    );
+
+    $this->assertEqual(
+      $expect,
+      ArcanistSubversionAPI::escapeFileNamesForSVN($input));
+  }
+
+}
index 2802e7ac51634d8694fe215bdaed3efaabcadb23..ab6872506709709ca74a2ce1ff6c492ea08aab1d 100644 (file)
@@ -245,10 +245,8 @@ EOTEXT
       $this->promptFileWarning($prefix, $prompt, $do_not_exist);
     }
 
-    $files = array();
-    foreach ($commit_paths as $file => $ignored) {
-      $files[] = $file.'@'; // make SVN accept commits like foo@2x.png
-    }
+    $files = array_keys($commit_paths);
+    $files = ArcanistSubversionAPI::escapeFileNamesForSVN($files);
 
     if (empty($files)) {
       throw new ArcanistUsageException(