summaryrefslogtreecommitdiff
path: root/builtin/difftool.c
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2021-09-23 04:12:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-09-23 18:24:41 (GMT)
commit5bafb3576ac8eb8464ddd5cc14a1211aaa46364b (patch)
tree0dbdd024c93328a720f0b22f12e227fc0f89c9ce /builtin/difftool.c
parentebf3c04b262aa27fbb97f8a0156c2347fecafafb (diff)
downloadgit-5bafb3576ac8eb8464ddd5cc14a1211aaa46364b.zip
git-5bafb3576ac8eb8464ddd5cc14a1211aaa46364b.tar.gz
git-5bafb3576ac8eb8464ddd5cc14a1211aaa46364b.tar.bz2
difftool: fix symlink-file writing in dir-diff mode
The difftool dir-diff mode handles symlinks by replacing them with their readlink(2) values. This allows diff tools to see changes to symlinks as if they were regular text diffs with the old and new path values. This is analogous to what "git diff" displays when symlinks change. The temporary diff directories that are created initially contain symlinks because they get checked-out using a temporary index that retains the original symlinks as checked-in to the repository. A bug was introduced when difftool was rewritten in C that made difftool write the readlink(2) contents into the pointed-to file rather than the symlink itself. The write was going through the symlink and writing to its target rather than writing to the symlink path itself. Replace symlinks with raw text files by unlinking the symlink path before writing the readlink(2) content into them. When 18ec800512 (difftool: handle modified symlinks in dir-diff mode, 2017-03-15) added handling for modified symlinks this bug got recorded in the test suite. The tests included the pointed-to symlink target paths. These paths were being reported because difftool was erroneously writing to them, but they should have never been reported nor written. Correct the modified-symlinks test cases by removing the target files from the expected output. Add a test to ensure that symlinks are written with the readlink(2) values and that the target files contain their original content. Reported-by: Alan Blotz <work@blotz.org> Helped-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/difftool.c')
-rw-r--r--builtin/difftool.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 89334b7..843d1fa 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -562,11 +562,13 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
if (*entry->left) {
add_path(&ldir, ldir_len, entry->path);
ensure_leading_directories(ldir.buf);
+ unlink(ldir.buf);
write_file(ldir.buf, "%s", entry->left);
}
if (*entry->right) {
add_path(&rdir, rdir_len, entry->path);
ensure_leading_directories(rdir.buf);
+ unlink(rdir.buf);
write_file(rdir.buf, "%s", entry->right);
}
}