aboutsummaryrefslogtreecommitdiff
path: root/t/t4015-diff-whitespace.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-02-04 13:23:06 -0800
committerJunio C Hamano <gitster@pobox.com>2026-02-05 20:36:48 -0800
commit6a41481c6de1cedb059930a710896c5ab2508a12 (patch)
tree96096a5a495420b2c24a1d785cd86554eb755cfa /t/t4015-diff-whitespace.sh
parent51358a1ede7f4b6b50e4e5a86558af5204691fe0 (diff)
downloadgit-6a41481c6de1cedb059930a710896c5ab2508a12.tar.xz
whitespace: symbolic links usually lack LF at the end
For a patch that touches a symbolic link, it is perfectly normal that the contents ends with "\ No newline at end of file". The checks introduced recently to detect incomplete lines (i.e., a text file that lack the newline on its final line) should not trigger. Disable the check early for symbolic links, both in "git apply" and "git diff" and test them. For "git apply", we check only when the postimage is a symbolic link regardless of the preimage, and we only care about preimage when applying in reverse. Similarly, "git diff" would warn only when the postimage is a symbolic link, or the preimage when running "git diff -R". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4015-diff-whitespace.sh')
-rwxr-xr-xt/t4015-diff-whitespace.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 3c8eb02e4f..b691d29479 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -90,6 +90,32 @@ test_expect_success "new incomplete line in post-image" '
git -c core.whitespace=incomplete diff -R --check x
'
+test_expect_success SYMLINKS "incomplete-line error is disabled for symlinks" '
+ test_when_finished "git reset --hard" &&
+ test_when_finished "rm -f mylink" &&
+
+ # a regular file with an incomplete line
+ printf "%s" one >mylink &&
+ git add mylink &&
+
+ # a symbolic link
+ rm mylink &&
+ ln -s two mylink &&
+
+ git -c diff.color=always -c core.whitespace=incomplete \
+ diff mylink >forward.raw &&
+ test_decode_color >forward <forward.raw &&
+ test_grep ! "<BRED>\\\\ No newline at end of file<RESET>" forward &&
+
+ git -c diff.color=always -c core.whitespace=incomplete \
+ diff -R mylink >reverse.raw &&
+ test_decode_color >reverse <reverse.raw &&
+ test_grep "<BRED>\\\\ No newline at end of file<RESET>" reverse &&
+
+ git -c core.whitespace=incomplete diff --check mylink &&
+ test_must_fail git -c core.whitespace=incomplete diff --check -R mylink
+'
+
test_expect_success "Ray Lehtiniemi's example" '
cat <<-\EOF >x &&
do {