@matheusbsbs / matheus-bagliano / commits / 418566b6fd
Fork 0

Fix 'git diff --no-index' with a non-existing symlink target

When trying to find out mode changes, we should not access the symlink targets using stat(); instead we use lstat() so that the diff does not fail trying to find a non-existing symlink target. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 29, 2009 at 17:30 UTC 418566b6fdcc0eb1b5549d0742366aa13a7ff277
2 files changed +8 -1
diff-no-index.c
+1 -1
@@ -40,7 +40,7 @@ static int get_mode(const char *path, int *mode)
40 *mode = 0;
41 else if (!strcmp(path, "-"))
42 *mode = create_ce_mode(0666);
43 - else if (stat(path, &st))
43 + else if (lstat(path, &st))
44 return error("Could not access '%s'", path);
45 else
46 *mode = st.st_mode;
t/t4011-diff-symlink.sh
+7
@@ -82,4 +82,11 @@ test_expect_success \
82 git diff-index -M -p $tree > current &&
83 compare_diff_patch current expected'
84
85 +test_expect_success \
86 + 'diff symlinks with non-existing targets' \
87 + 'ln -s narf pinky &&
88 + ln -s take\ over brain &&
89 + test_must_fail git diff --no-index pinky brain > output 2> output.err &&
90 + grep narf output &&
91 + ! grep error output.err'
92 test_done