git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: improvement to pre-commit hook

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
May 20, 2019, 23:45 UTC
Message-ID
<20190520234509.GB8616@genre.crustytoothpaste.net>
In-Reply-To
<CAMsBkhmt0Xxe7EHSXJjxeZa4-CmF8oVgJiTFo2uHQOMcyKfCvw@mail.gmail.com>
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
Previous: Olegzandr von Denman (ORESoftware)
Message 2 of 2 in “improvement to pre-commit hook”
  1. Olegzandr von Denman (ORESoftware)May 19, 2019
  2. brian m. carlsonMay 20, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.