]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve representation of replaced symlinks in Git
authorepriestley <git@epriestley.com>
Fri, 21 Oct 2011 19:37:40 +0000 (12:37 -0700)
committerepriestley <git@epriestley.com>
Tue, 25 Oct 2011 06:38:56 +0000 (23:38 -0700)
Summary:
See T584. Git renders these types of changes somewhat unusually. Ensure they are
rendered as changes.

The fact that a symlink was replaced is not explicitly rendered (e.g., "This
path was changed from a symlink to a regular file."), but can be inferred from
the 'unix:filemode' property change that will accompany the changeset. We could
also make it explicit but this type of change is rare enough that it's probably
good enough as-is.

Test Plan:
  - Ran unit test, which previously failed and now passes.
  - Created a diff which replaces a file with a symlink, verified it rendered a
little more sensibly.

Reviewers: aravindn, dschleimer, jungejason, nh, tuomaspelkonen

Reviewed By: nh

CC: aran, goldshlager, nh
Differential Revision: 1030

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

index 3c82cf544ec6b2d876f898759e3b585de9affd23..f828fc4ba3cccc2f8e7cee687aa56710ba26b044 100644 (file)
@@ -503,7 +503,14 @@ class ArcanistDiffParser {
         }
 
         if (!empty($match['new'])) {
-          $change->setType(ArcanistDiffChangeType::TYPE_ADD);
+          // If you replace a symlink with a normal file, git renders the change
+          // as a "delete" of the symlink plus an "add" of the new file. We
+          // prefer to represent this as a change.
+          if ($change->getType() == ArcanistDiffChangeType::TYPE_DELETE) {
+            $change->setType(ArcanistDiffChangeType::TYPE_CHANGE);
+          } else {
+            $change->setType(ArcanistDiffChangeType::TYPE_ADD);
+          }
         }
 
         if (!empty($match['old'])) {
index f976182dcce30b8a38e26d866754cf7f66b8df82..552426045c71e10d1734f6576cd1e02e0f31ccaf 100644 (file)
@@ -487,6 +487,13 @@ EOTEXT
           ArcanistDiffChangeType::FILE_BINARY,
           $change->getFileType());
         break;
+      case 'git-replace-symlink.gitdiff':
+        $this->assertEqual(1, count($changes));
+        $change = array_shift($changes);
+        $this->assertEqual(
+          ArcanistDiffChangeType::TYPE_CHANGE,
+          $change->getType());
+        break;
       default:
         throw new Exception("No test block for diff file {$diff_file}.");
         break;
diff --git a/src/parser/diff/__tests__/data/git-replace-symlink.gitdiff b/src/parser/diff/__tests__/data/git-replace-symlink.gitdiff
new file mode 100644 (file)
index 0000000..804be27
--- /dev/null
@@ -0,0 +1,15 @@
+diff --git a/derp b/derp
+deleted file mode 120000
+index d6d9d34..0000000
+--- a/derp
++++ /dev/null
+@@ -1 +0,0 @@
+-blah
+\ No newline at end of file
+diff --git a/derp b/derp
+new file mode 100644
+index 0000000..54a5dbc
+--- /dev/null
++++ b/derp
+@@ -0,0 +1 @@
++derp derp