Re: [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error
- From
Bello Olamide <belkid98@gmail.com>
- Date
- Oct 12, 2025, 23:41 UTC
- Message-ID
- <CAD=f0L-QAfMhBw1_RyLkpdntjPfu4M+temmawWGEZjAJn_iQdQ@mail.gmail.com>
- In-Reply-To
- <xmqqecr95ib0.fsf@gitster.g>
On Sat, 11 Oct 2025 at 20:50, Junio C Hamano <gitster@pobox.com> wrote:
Show 22 quoted lines
> > 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. >
Hello Junio, Thank you for your response. I will take these into account.
Show 25 quoted lines
> 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.Thank you for the clarity. This would mean to compare the relevant files in the current commit with its parent commit and report when the current commit removes the new line at the end of file which was present in the parent commit.
But how about when a file is newly added and lacks the new line?
Show 8 quoted lines
> > 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.
Thank you very much. I perfectly understand this now. The right way would be the better way as we can just parse the output in check-whitespace and it will be more interesting to work on, as it would greatly increase my knowledge on Git internals. If this would be too big for a microproject, I will look up a task fitting for a microproject and then push forward with this.
Thank you for your time, Bello