git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 11, 2025, 19:50 UTC
Message-ID
<xmqqecr95ib0.fsf@gitster.g>
In-Reply-To
<aOporVVSRRL/v4Lq@ubuntu>
Bello Caleb Olamide <belkid98@gmail.com> writes:
> Hello,
>
> While going through the mailing list for some #leftoverbits, I stumbled on this converation.
> https://public-inbox.org/git/xmqqikla86id.fsf@gitster.g/.

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.
Show 8 quoted lines
> 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.

Previous: Bello Caleb OlamideNext: Bello Olamide
Message 2 of 4 in “[RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error”
  1. Bello Caleb OlamideOct 11, 2025
  2. Junio C HamanoOct 11, 2025
  3. Bello OlamideOct 12, 2025
  4. Junio C HamanoOct 13, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.