From: epriestley Date: Fri, 21 Oct 2011 19:37:40 +0000 (-0700) Subject: Improve representation of replaced symlinks in Git X-Git-Tag: conduit-4~263 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a85e3444259146ac6f8a28516d000b883ad94976;p=arcanist.git Improve representation of replaced symlinks in Git 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 --- diff --git a/src/parser/diff/ArcanistDiffParser.php b/src/parser/diff/ArcanistDiffParser.php index 3c82cf54..f828fc4b 100644 --- a/src/parser/diff/ArcanistDiffParser.php +++ b/src/parser/diff/ArcanistDiffParser.php @@ -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'])) { diff --git a/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php b/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php index f976182d..55242604 100644 --- a/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php +++ b/src/parser/diff/__tests__/ArcanistDiffParserTestCase.php @@ -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 index 00000000..804be275 --- /dev/null +++ b/src/parser/diff/__tests__/data/git-replace-symlink.gitdiff @@ -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