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

Re: hook to get info on commit, and include that in a file that is part of the commit

From
Larry Martell <larry.martell@gmail.com>
Date
Feb 5, 2019, 02:00 UTC
Message-ID
<CACwCsY4fwr6=2S5CHe5bH7=7Hukq9np+eT1VO+kUDyBtMLKPcA@mail.gmail.com>
In-Reply-To
<20190205015506.GB527887@genre.crustytoothpaste.net>

On Mon, Feb 4, 2019 at 8:55 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 25 quoted lines
>
> On Mon, Feb 04, 2019 at 08:36:10PM -0500, Larry Martell wrote:
> > Is there any way using a git hook to get info on the commit (id,
> > message), put that in a file, and include that file in the commit?
> >
> > If I try that in a pre-commit hook I do not get the info on the
> > current commit. I tried it in pre-receive but it does not seem to get
> > executed at all.
>
> You cannot include a file in the commit with that commit's ID.
>
> The object ID of a commit is based on the data it contains, which is in
> turn based on the data in its top-level tree, which is in turn based on
> the data in all of its trees and blobs. If you add or change a file in a
> commit (or the message of that commit), you necessarily result in that
> commit having a different object ID. This is by design and is valuable
> for checking the integrity of the history.
>
> Furthermore, the hooks for a commit are designed for checking and
> notification, not for editing the commit, with the exception of the
> commit message hooks, which are designed only for editing the commit
> message, not the contents.
>
> The pre-receive hook runs on the server side, so if you aren't running
> it there, then it won't get called at all.
Thanks for the reply. Any suggestions on how to achieve what I want to do?

The use case is that we want to have a file that is part of the install that has certain info (commit id, date of commit, commit message, etc.). and we'd like that to be generated automatically.

Previous: brian m. carlsonNext: brian m. carlson
Message 3 of 7 in “hook to get info on commit, and include that in a file that is part of the commit”
  1. Larry MartellFeb 5, 2019
  2. brian m. carlsonFeb 5, 2019
  3. Larry MartellFeb 5, 2019
  4. brian m. carlsonFeb 5, 2019
  5. Larry MartellFeb 5, 2019
  6. brian m. carlsonFeb 5, 2019
  7. Larry MartellFeb 5, 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.