threads / discuss / 51126

improvement to pre-commit hook

Subject: improvement to pre-commit hook

## tl;dr

2 messages between May 19, 2019 and May 20, 2019.

replies: 1people: 2as markdown or json

Olegzandr von Denman (ORESoftware)· May 19, 2019, 06:03 UTC · lore
I was expected an env var like:
GIT_DESIRED_COMMIT_MESSAGE
to show up when .git/hooks/pre-commit is run

but as described here, there doesn't appear to be any args to the script and the environment variable isn't there?

https://stackoverflow.com/questions/56205170/retrieving-desired-git-commit-message-in-pre-commit-hook
-alex
-- 
Alexander Mills
ORESoftware (inc.)
brian m. carlson· May 20, 2019, 23:45 UTC · re: Olegzandr von Denman (ORESoftware) · lore

Re: improvement to pre-commit hook

On 2019-05-19 at 06:03:11, Olegzandr von Denman (ORESoftware) wrote:
Show 10 quoted lines
> I was expected an env var like:
> 
> GIT_DESIRED_COMMIT_MESSAGE
> 
> to show up when .git/hooks/pre-commit is run
> 
> but as described here, there doesn't appear to be any args to the
> script and the environment variable isn't there?
> 
> https://stackoverflow.com/questions/56205170/retrieving-desired-git-commit-message-in-pre-commit-hook

In general, the pre-commit hook isn't the right place to inspect the commit message. If the user hasn't specified the commit message on the command line, then they will be prompted for it using their editor, and there will be nothing to process.

Furthermore, since the prepare-commit-msg hook hasn't run, there could be arbitrary changes to the commit message after the pre-commit hook runs. You'd want to use the prepare-commit-msg hook to modify the commit message and then use the commit-msg hook to accept or reject it. Despite the name, the commit-msg hook can be used to perform arbitrary analysis of the commit and reject it for any reason if you require the commit message to do so.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

← back to recent threads