summaryrefslogtreecommitdiffstats
path: root/t/t3701-add-interactive.sh
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2024-07-20 18:01:59 +0200
committerJunio C Hamano <gitster@pobox.com>2024-07-21 01:29:14 +0200
commit39bdd84eaf646aa73a3709b0eb8be3f47378708f (patch)
treec08b998aceb46bf881b76ed23525f262a1b4801d /t/t3701-add-interactive.sh
parentGit 2.43.5 (diff)
downloadgit-39bdd84eaf646aa73a3709b0eb8be3f47378708f.tar.xz
git-39bdd84eaf646aa73a3709b0eb8be3f47378708f.zip
add-patch: handle splitting hunks with diff.suppressBlankEmpty
When "add -p" parses diffs, it looks for context lines starting with a single space. But when diff.suppressBlankEmpty is in effect, an empty context line will omit the space, giving us a true empty line. This confuses the parser, which is unable to split based on such a line. It's tempting to say that we should just make sure that we generate a diff without that option. However, although we do not parse hunks that the user has manually edited with parse_diff() we do allow the user to split such hunks. As POSIX calls the decision of whether to print the space here "implementation-defined" we need to handle edited hunks where empty context lines omit the space. So let's handle both cases: a context line either starts with a space or consists of a totally empty line by normalizing the first character to a space when we parse them. Normalizing the first character rather than changing the code to check for a space or newline will hopefully future proof against introducing similar bugs if the code is changed. Reported-by: Ilya Tumaykin <itumaykin@gmail.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rwxr-xr-xt/t3701-add-interactive.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 0b5339ac6c..4c3e2bc82f 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -1130,4 +1130,23 @@ test_expect_success 'reset -p with unmerged files' '
test_must_be_empty staged
'
+test_expect_success 'hunk splitting works with diff.suppressBlankEmpty' '
+ test_config diff.suppressBlankEmpty true &&
+ write_script fake-editor.sh <<-\EOF &&
+ tr F G <"$1" >"$1.tmp" &&
+ mv "$1.tmp" "$1"
+ EOF
+
+ test_write_lines a b "" c d "" e f "" >file &&
+ git add file &&
+ test_write_lines A b "" c D "" e F "" >file &&
+ (
+ test_set_editor "$(pwd)/fake-editor.sh" &&
+ test_write_lines s n y e q | git add -p file
+ ) &&
+ git cat-file blob :file >actual &&
+ test_write_lines a b "" c D "" e G "" >expect &&
+ test_cmp expect actual
+'
+
test_done