Re: Should commit-msg hook receive the washed message?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
> 
> The idea you proposed in a different thread[2] of exposing
> cleanup_message() functionality as a user-facing utility which a hook
> can call on an as-needed basis may make more sense(?).
> 
> [2]: https://lore.kernel.org/git/m034onpng4.fsf@xxxxxxxxxxxxxxxxxx/

I don't think that would suffice for our use case. Specifically, the
commit-msg hook has no way to know if it's looking at a message that
will be washed, or will not. For example, let's say a commit-msg hook
aims to enforce a 72-character hard-wrap policy. If a line starts with
`#`, what is the hook supposed to do?

- If the commit was created using `git commit` and the user's normal
  editor is invoked, the hook should *not* evaluate any line starting
  with `#` because that line will be removed prior to creating the
  commit as part of the message washing process.
- If the commit was created using `git commit -m`, the hook *should*
  evaluate any line starting with `#` because that line will not be
  removed by washing.

This challenge also exists for the patch scissors and any content
following it. That could have been added by git because the user called
`git commit -v` (most likely), but it also could in theory have been
added by the user, in which case the patch (or patch-like content) ends
up in the final commit message as well. The hook has no way to know
whether the commit was initiated via `git commit -v` or not. The
real-world use case here could be a commit-msg hook that adds a trailer:
if the patch will be removed during washing, then using `git
interpret-trailers` to add the trailer (which places it *before* the
patch) is fine. If the patch will not be removed during washing, then 
`git interpret-trailers` ends up putting the trailer in the middle of
the final message between the subject/body and the patch, then the patch
isn't removed and thus it's not a valid trailer.

Ultimately, the hook doesn't know what will happen to the message after
it runs, and thus doesn't know if a given line is guaranteed to be part
of the final commit message. This presents these edge case challenges
when attempting to implement the hook.

If the hook either were always called with the final proposed commit
message, or if it knew that the message would be washed after being
executed, then we'd have options for handling these edge cases.

-- 
Thanks,
Brian Lyles





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux