Subject: Re: [PATCH v4 4/4] add-patch: add diff.context command line overrides

From: Phillip Wood <[email-masked]>
Date: Wed, 23 Jul 2025 10:41:51 +0100

Hi Leon

Here is a fixup commit for the tests which can be squashed into patch 4

Best Wishes

Phillip

---- 8< ----
From: Phillip Wood <[email-masked]>
Subject: [PATCH] fixup! add-patch: add diff.context command line overrides

Restore the test coverage for diff.context and diff.interHunkContext
added in f08d4ae6e56 (add-patch: respect diff.context configuration,
2025-07-19) and remove the redunant tests in t4055 added by bd6d6ba1321
(add-patch: add diff.context command line overrides, 2025-07-19) which
duplicate the coverage of the tests added to t3071 in the same commit.

Signed-off-by: Phillip Wood <[email-masked]>
---
 t/t3701-add-interactive.sh | 22 ++++++++++++++++++++++
 t/t4055-diff-context.sh    | 30 ------------------------------
 2 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 7fd9a23c998..04d2a198352 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -1230,6 +1230,28 @@ test_expect_success 'hunk splitting works with diff.suppressBlankEmpty' '
 	test_cmp expect actual
 '
 
+test_expect_success 'add -p respects diff.context' '
+	test_write_lines a b c d e f g h i j k l m >file &&
+	git add file &&
+	test_write_lines a b c d e f G h i j k l m >file &&
+	echo y | git -c diff.context=5 add -p >actual &&
+	test_grep "@@ -2,11 +2,11 @@" actual
+'
+
+test_expect_success 'add -p respects diff.interHunkContext' '
+	test_write_lines a b c d e f g h i j k l m n o p q r s >file &&
+	git add file &&
+	test_write_lines a b c d E f g i i j k l m N o p q r s >file &&
+	echo y | git -c diff.interhunkcontext=2 add -p >actual &&
+	test_grep "@@ -2,16 +2,16 @@" actual
+'
+
+test_expect_success 'add -p rejects negative diff.context' '
+	test_config diff.context -1 &&
+	test_must_fail git add -p 2>output &&
+	test_grep "diff.context cannot be negative" output
+'
+
 for cmd in add checkout restore 'commit -m file'
 do
 	test_expect_success "${cmd%% *} accepts -U and --inter-hunk-context" '
diff --git a/t/t4055-diff-context.sh b/t/t4055-diff-context.sh
index 0158fe6568c..1384a819570 100755
--- a/t/t4055-diff-context.sh
+++ b/t/t4055-diff-context.sh
@@ -58,36 +58,6 @@ test_expect_success 'The -U option overrides diff.context' '
 	test_grep ! "^ firstline" output
 '
 
-test_expect_success 'The -U option overrides diff.context for "add"' '
-	test_config diff.context 8 &&
-	git add -U4 -p >output &&
-	test_grep ! "^ firstline" output
-'
-
-test_expect_success 'The -U option overrides diff.context for "commit"' '
-	test_config diff.context 8 &&
-	! git commit -U4 -p >output &&
-	test_grep ! "^ firstline" output
-'
-
-test_expect_success 'The -U option overrides diff.context for "checkout"' '
-	test_config diff.context 8 &&
-	git checkout -U4 -p >output &&
-	test_grep ! "^ firstline" output
-'
-
-test_expect_success 'The -U option overrides diff.context for "stash"' '
-	test_config diff.context 8 &&
-	! git stash -U4 -p >output &&
-	test_grep ! "^ firstline" output
-'
-
-test_expect_success 'The -U option overrides diff.context for "restore"' '
-	test_config diff.context 8 &&
-	git restore -U4 -p >output &&
-	test_grep ! "^ firstline" output
-'
-
 test_expect_success 'diff.context honored by "diff"' '
 	test_config diff.context 8 &&
 	git diff >output &&
-- 
2.49.0.897.gfad3eb7d210