diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-04-07 14:59:26 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-04-07 14:59:26 -0700 |
| commit | 55d867c547895b17af0093b339673c16e09a2042 (patch) | |
| tree | f5ac967a337acc42f8a046fb93147ddfde0062fd | |
| parent | d88c8ba70bbcbc45a31cf05034a8e0c6884fb3d3 (diff) | |
| parent | afdb4c665f664e04c0f68c930ad50e5b05be71e1 (diff) | |
| download | git-55d867c547895b17af0093b339673c16e09a2042.tar.xz | |
Merge branch 'jc/whitespace-incomplete-line'
Fix whitespace correction for new-style empty context lines.
* jc/whitespace-incomplete-line:
apply: fix new-style empty context line triggering incomplete-line check
| -rw-r--r-- | apply.c | 12 | ||||
| -rwxr-xr-x | t/t4124-apply-ws-rule.sh | 16 |
2 files changed, 26 insertions, 2 deletions
@@ -1840,8 +1840,16 @@ static int parse_fragment(struct apply_state *state, trailing++; check_old_for_crlf(patch, line, len); if (!state->apply_in_reverse && - state->ws_error_action == correct_ws_error) - check_whitespace(state, line, len, patch->ws_rule); + state->ws_error_action == correct_ws_error) { + const char *test_line = line; + int test_len = len; + if (*line == '\n') { + test_line = " \n"; + test_len = 2; + } + check_whitespace(state, test_line, test_len, + patch->ws_rule); + } break; case '-': if (!state->apply_in_reverse) diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index 29ea7d4268..205d86d05e 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -561,6 +561,22 @@ test_expect_success 'check incomplete lines (setup)' ' git config core.whitespace incomplete-line ' +test_expect_success 'no incomplete context line (not an error)' ' + test_when_finished "rm -f sample*-i patch patch-new target" && + test_write_lines 1 2 3 "" 4 5 >sample-i && + test_write_lines 1 2 3 "" 0 5 >sample2-i && + cat sample-i >target && + git add target && + cat sample2-i >target && + git diff-files -p target >patch && + sed -e "s/^ $//" <patch >patch-new && + + cat sample-i >target && + git apply --whitespace=fix <patch-new 2>error && + test_cmp sample2-i target && + test_must_be_empty error +' + test_expect_success 'incomplete context line (not an error)' ' (test_write_lines 1 2 3 4 5 && printf 6) >sample-i && (test_write_lines 1 2 3 0 5 && printf 6) >sample2-i && |
