{"thread":{"id":"17440","subject":"[PATCH] Fix 'git diff --no-index' with a non-existing symlink target","startedAt":"2009-01-29T16:30:51Z","lastAt":"2009-01-29T16:30:51Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"102475","messageId":"alpine.DEB.1.00.0901291730210.3586@pacific.mpi-cbg.de","threadId":"17440","inReplyTo":"cover.1233246616u.git.johannes.schindelin@gmx.de","subject":"[PATCH] Fix 'git diff --no-index' with a non-existing symlink target","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-29T16:30:51Z","receivedAt":"2009-01-29T16:30:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When trying to find out mode changes, we should not access the symlink\ntargets using stat(); instead we use lstat() so that the diff does\nnot fail trying to find a non-existing symlink target.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n diff-no-index.c         |    2 +-\n t/t4011-diff-symlink.sh |    7 +++++++\n 2 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 60ed174..0dbd9da 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -40,7 +40,7 @@ static int get_mode(const char *path, int *mode)\n \t\t*mode = 0;\n \telse if (!strcmp(path, \"-\"))\n \t\t*mode = create_ce_mode(0666);\n-\telse if (stat(path, &st))\n+\telse if (lstat(path, &st))\n \t\treturn error(\"Could not access '%s'\", path);\n \telse\n \t\t*mode = st.st_mode;\ndiff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh\nindex 02efeca..9055c8b 100755\n--- a/t/t4011-diff-symlink.sh\n+++ b/t/t4011-diff-symlink.sh\n@@ -82,4 +82,11 @@ test_expect_success \\\n     git diff-index -M -p $tree > current &&\n     compare_diff_patch current expected'\n \n+test_expect_success \\\n+    'diff symlinks with non-existing targets' \\\n+    'ln -s narf pinky &&\n+    ln -s take\\ over brain &&\n+    test_must_fail git diff --no-index pinky brain > output 2> output.err &&\n+    grep narf output &&\n+    ! grep error output.err'\n test_done\n-- \n1.6.1.2.531.g6f52\n"}]}