From 498198453dbb8ae46becbc83a1ef0979a0eb805d Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 5 Jul 2023 20:49:27 +0100 Subject: diff --no-index: refuse to compare stdin to a directory When the user runs git diff --no-index file directory we follow the behavior of POSIX diff and rewrite the arguments as git diff --no-index file directory/file Doing that when "file" is "-" (which means "read from stdin") does not make sense so we should error out if the user asks us to compare "-" to a directory. This matches the behavior of GNU diff and diff on *BSD. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- t/t4053-diff-no-index.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't') diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh index 4e9fa0403d..5bfb282e98 100755 --- a/t/t4053-diff-no-index.sh +++ b/t/t4053-diff-no-index.sh @@ -205,4 +205,9 @@ test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not lik test_cmp expected actual ' +test_expect_success 'diff --no-index refuses to diff stdin and a directory' ' + test_must_fail git diff --no-index -- - a err && + grep "fatal: cannot compare stdin to a directory" err +' + test_done -- cgit v1.3-5-g9baa