Re: [PATCH] apply: fix new-style empty context line triggering incomplete-line check
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 17, 2026, 18:12 UTC
- Message-ID
- <CAPig+cTTgLVGPG99gsb19BeJVWS=VZCU4F-rjb25yHTAORWwzg@mail.gmail.com>
- In-Reply-To
- <xmqqldfql4hp.fsf@gitster.g>
On Tue, Mar 17, 2026 at 2:01 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 28 quoted lines
> 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> > --- > diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh > index 29ea7d4268..8573e12f46 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)' ' > +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 &&
Curious. Why are the `test_write_line` invocations wrapped in parentheses?
Also, is the whitespace before the closing parenthesis intentional?
> 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 &&
Perhaps the parentheses in the new test were copied from some existing test, such as this, which already used them for a legitimate reason?