diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-03-17 11:01:38 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-17 11:46:47 -0700 |
| commit | afdb4c665f664e04c0f68c930ad50e5b05be71e1 (patch) | |
| tree | ef9a19c5e5ab6eb01303a3a0f77432d653278645 /apply.c | |
| parent | 6a41481c6de1cedb059930a710896c5ab2508a12 (diff) | |
| download | git-afdb4c665f664e04c0f68c930ad50e5b05be71e1.tar.xz | |
apply: fix new-style empty context line triggering incomplete-line check
A new-style unified context diff represents an empty context line
with an empty line (instead of a line with a single SP on it). The
code to check whitespace errors in an incoming patch is designed to
omit the first byte of a line (typically SP, "-", or "+") and pass the
remainder of the line to the whitespace checker.
Usually we do not pass a context line to the whitespace error checker,
but when we are correcting errors, we do. This "remove the first
byte and send the remainder" strategy of checking a line ended up
sending a zero-length string to the whitespace checker when seeing a
new-style empty context line, which caused the whitespace checker to
say "ah, you do not even have a newline at the end!", leading to an
"incomplete line" in the middle of the patch!
Fix this by pretending that we got a traditional empty context line
when we drive the whitespace checker.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'apply.c')
| -rw-r--r-- | apply.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -1796,8 +1796,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) |
