Subject: Re: [BUG REPORT] git-gui invokes prepare-commit-msg hook incorrectly

From: Junio C Hamano <[email-masked]>
Date: Sat, 06 Jul 2024 11:15:04 -0700

Johannes Sixt <[email-masked]> writes:

> My take-away is:
>
> - The commit message that is entered in the edit box must appear in the
> commit unmodified. There is no such concept as "comment lines" in git
> gui's commit message edit box. The commit-msg hook can overrule
> nevertheless as a means to enforce message hygiene, but otherwise the
> user must have full authority.
>
> - A commit message template and the MERGE_MSG file are populated in a
> manner that is suitable for `git commit`, i.e. can (and do) contain
> comment lines. It is, therefore, necessary to remove them when their
> text is used to populate git gui's edit box.
>
> I suggest that removing comment lines ("message-washing") should not
> happen as a post-processing step, but as a preprocessing step when text
> is gathered from particular sources that are known to contain
> inessential cruft.

I agree most of the things you said, but with one reservation.

There may be two classes of comments CLI "git commit" users would be
seeing, ones coming from the "git commit" itself that describe what
CLI "git commit" does (e.g., "lines starting with '#' are ignored",
"absolutely empty message buffer aborts the command"), and others
coming from project specific template and other mechanisms that
describe what the project expects (e.g., "please keep your lines
shorter than 72 columns").

I agree that it makes perfect sense not to show the former at all to
the end-user in git-gui UI, especially if git-gui does not ignore
lines starting with '#' or abort commit with an empty message.

I am not sure if it is safe to strip the latter out of user's view,
though.