Subject: Re: [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error

From: Junio C Hamano <[email-masked]>
Date: Sat, 11 Oct 2025 12:50:43 -0700

Bello Caleb Olamide <[email-masked]> writes:

> Hello,
>
> While going through the mailing list for some #leftoverbits, I stumbled on this converation.
> https://public-inbox.org/git/[email-masked]/.

Welcome, and first please learn to keep your lines under readable
width limit.  As an applicant to a mentoring program with this
project, you will be exchanging e-mails about patches, whose
contents are limited to 80 columns (but subtracting 1 columns for
"+/ /-" prefix when a line is shown in a patch, plus several more
for "> " prefix when the message is quoted multiple times during a
discussion thread, a practical line-length limit is more like 68-72
columns), and you will be adding in-line comments in the middle of
quoted patches.

Hence, your comments in e-mails thrown at this list are also limited
to similar line length limit.  Otherwise they would become very hard
to read.

I'll line-wrap the quoted text below.

> After studying the check-whitespace script, I observed that the
> script parses each line of the output of the command `git log
> --check --pretty=format:"---% h% s" "${baseCommit}"..` and formats
> the result.
>
> But the output of the git command itself does not flag '\no
> newline at end of file' as it is shown in git diff, in a case
> where the files does not contain a newline at the end of the file.

Correct observations.

> One approach I propose to take is to check the each file changed
> in each commit and check if it has the \n as the last character.

If a commit changes line 4 of a 100-line file that lacked the final
newline, "git log" would show the commit, "git log -p" would show a
patch to the file, but "\No newline" would not be shown, because the
commit is not responsible for introducing an incomplete line to the
file.  Looking at the last byte of "git cat-file blob $commit:$path"
for commits that appear in "git log" output would not give us what
we want.  We need a mechanism that notices and warns when a commit
makes a file, which used to end with a newline, end in an incomplete
line.

If you can come up with a robust way to do so in check-whitespace
script, with the understanding that the right solution in the longer
term is to teach "git log --check" to notice incomplete lines and
flag it (with core.whitespace configuration and the whitespace
attributes to enable/disable the check), it might work as a stop-gap
measure.  As I said elsewhere a few days ago, doing it right would
be a bit too big for a microproject.