diff mbox series

[v2,1/3] t4020: test exit code with external diffs

Message ID 2a5167fc-871b-4968-bacb-eaff4d7a2630@web.de (mailing list archive)
State Superseded
Headers show
Series diff: fix --exit-code with external diff | expand

Commit Message

René Scharfe June 5, 2024, 8:35 a.m. UTC
Add tests to check the exit code of git diff with its options --quiet
and --exit-code when using an external diff program.  Currently we
cannot tell whether it found significant changes or not.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 t/t4020-diff-external.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

--
2.45.2
diff mbox series

Patch

diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh
index fdd865f7c3..bed640b2b1 100755
--- a/t/t4020-diff-external.sh
+++ b/t/t4020-diff-external.sh
@@ -172,6 +172,39 @@  test_expect_success 'no diff with -diff' '
 	grep Binary out
 '

+check_external_exit_code () {
+	expect_code=$1
+	command_code=$2
+	option=$3
+
+	command="exit $command_code;"
+	desc="external diff '$command'"
+
+	test_expect_success "$desc via attribute with $option" "
+		test_config diff.foo.command \"$command\" &&
+		echo \"file diff=foo\" >.gitattributes &&
+		test_expect_code $expect_code git diff $option
+	"
+
+	test_expect_success "$desc via diff.external with $option" "
+		test_config diff.external \"$command\" &&
+		>.gitattributes &&
+		test_expect_code $expect_code git diff $option
+	"
+
+	test_expect_success "$desc via GIT_EXTERNAL_DIFF with $option" "
+		>.gitattributes &&
+		test_expect_code $expect_code env \
+			GIT_EXTERNAL_DIFF=\"$command\" \
+			git diff $option
+	"
+}
+
+check_external_exit_code   1 0 --exit-code
+check_external_exit_code   1 0 --quiet
+check_external_exit_code 128 1 --exit-code
+check_external_exit_code   1 1 --quiet # we don't even call the program
+
 echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file

 test_expect_success 'force diff with "diff"' '