* [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error
@ 2025-10-11 14:24 Bello Caleb Olamide
2025-10-11 19:50 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Bello Caleb Olamide @ 2025-10-11 14:24 UTC (permalink / raw)
To: git; +Cc: gitster, christian.couder, usmanakinyemi202
Hello,
While going through the mailing list for some #leftoverbits, I stumbled on this converation.
https://public-inbox.org/git/xmqqikla86id.fsf@gitster.g/.
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.
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.
Please, will this be good for a microproject and also I'll appreciate suggestions for the approach.
Thank you.
Bello
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error 2025-10-11 14:24 [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error Bello Caleb Olamide @ 2025-10-11 19:50 ` Junio C Hamano 2025-10-12 23:41 ` Bello Olamide 0 siblings, 1 reply; 4+ messages in thread From: Junio C Hamano @ 2025-10-11 19:50 UTC (permalink / raw) To: Bello Caleb Olamide; +Cc: git, christian.couder, usmanakinyemi202 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. > 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. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error 2025-10-11 19:50 ` Junio C Hamano @ 2025-10-12 23:41 ` Bello Olamide 2025-10-13 15:41 ` Junio C Hamano 0 siblings, 1 reply; 4+ messages in thread From: Bello Olamide @ 2025-10-12 23:41 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, christian.couder, usmanakinyemi202 On Sat, 11 Oct 2025 at 20:50, Junio C Hamano <gitster@pobox.com> wrote: > > 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. > 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? > > 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error 2025-10-12 23:41 ` Bello Olamide @ 2025-10-13 15:41 ` Junio C Hamano 0 siblings, 0 replies; 4+ messages in thread From: Junio C Hamano @ 2025-10-13 15:41 UTC (permalink / raw) To: Bello Olamide; +Cc: git, christian.couder, usmanakinyemi202 Bello Olamide <belkid98@gmail.com> writes: >> 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? Yes, you should notice and flag any new incomplete line that did not exist before that are added by the commit. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-13 15:41 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-10-11 14:24 [RFC Outreachy] Teach ci/check-whitespace to flag incomplete lines as an error Bello Caleb Olamide 2025-10-11 19:50 ` Junio C Hamano 2025-10-12 23:41 ` Bello Olamide 2025-10-13 15:41 ` Junio C Hamano
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).