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

Re: HowTo distribute a hook with the reposity.

From
Jeff King <peff@peff.net>
Date
Dec 28, 2016, 09:20 UTC
Message-ID
<20161228092011.bnqqcvujescbdhji@sigill.intra.peff.net>
In-Reply-To
<39886f48-c48f-6800-8aa4-20e0b2ab0e6d@gmail.com>
On Wed, Dec 28, 2016 at 09:09:04AM +0000, John P. Hartmann wrote:
Show 8 quoted lines
> The problem I am grappling with is how to obtain the latest git commit hash
> and enter it into the generated code.  Configure/make would appear to the
> the time, but by then the user may not have git installed (e.g., extracted
> the project as .zip from github), so it needs to be done "back at the farm".
> 
> I hear that the best I can do is create a normal script in the repro and add
> to the developer handbook that "btw, here is a git hook that will run it
> automatically if you so choose".

Yes, if you want the information to be conveyed in a .zip from GitHub, then you'll have to commit the value to the repository. For example, the script in Git itself looks like this:

  https://github.com/git/git/blob/master/GIT-VERSION-GEN

We pull the value from the Git repository if we have one, then fallback to a .version file which is generated when release tarballs are generated, and then finally fall back to a baked-in DEF_VER variable that is updated manually after each release (and that last is what you'd get if you had, say, a .zip file from GitHub).

I'm not sure you would want to update that DEF_VER for _every_ commit, though, even if you could do so with a hook. It would mean every commit would update the version field. And of course it could not have the git commit id, because that is generated from a hash of the contents that includes the contents of that version field.

If you're mostly interested in building straight from GitHub .zip files, those do include the commit id (or tag name) in the directory name, so your Makefile could deduce it at runtime from that information.

-Peff
Previous: John P. HartmannNext: Jacob Keller
Message 7 of 9 in “HowTo distribute a hook with the reposity.”
  1. John P. HartmannDec 28, 2016
  2. Jacob KellerDec 28, 2016
  3. Jeff KingDec 28, 2016
  4. John P. HartmannDec 28, 2016
  5. Jeff KingDec 28, 2016
  6. John P. HartmannDec 28, 2016
  7. Jeff KingDec 28, 2016
  8. Jacob KellerDec 28, 2016
  9. Lars SchneiderDec 29, 2016

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.