git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 29, 2009, 16:30 UTC
Message-ID
<alpine.DEB.1.00.0901291730210.3586@pacific.mpi-cbg.de>
In-Reply-To
<cover.1233246616u.git.johannes.schindelin@gmx.de>

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>
---
 diff-no-index.c         |    2 +-
 t/t4011-diff-symlink.sh |    7 +++++++
 2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 60ed174..0dbd9da 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -40,7 +40,7 @@ static int get_mode(const char *path, int *mode)
 		*mode = 0;
 	else if (!strcmp(path, "-"))
 		*mode = create_ce_mode(0666);
-	else if (stat(path, &st))
+	else if (lstat(path, &st))
 		return error("Could not access '%s'", path);
 	else
 		*mode = st.st_mode;
diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh
index 02efeca..9055c8b 100755
--- a/t/t4011-diff-symlink.sh
+++ b/t/t4011-diff-symlink.sh
@@ -82,4 +82,11 @@ test_expect_success \
     git diff-index -M -p $tree > current &&
     compare_diff_patch current expected'
 
+test_expect_success \
+    'diff symlinks with non-existing targets' \
+    'ln -s narf pinky &&
+    ln -s take\ over brain &&
+    test_must_fail git diff --no-index pinky brain > output 2> output.err &&
+    grep narf output &&
+    ! grep error output.err'
 test_done
-- 
1.6.1.2.531.g6f52
Message 1 of 1 in “Fix 'git diff --no-index' with a non-existing symlink target”
  1. Fix 'git diff --no-index' with a non-existing symlink targetJohannes Schindelin, Jan 29, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.