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

Integrating with hooks

From
TJTodd A. Jacobs <nospam@codegnome.org>
Date
Nov 13, 2007, 17:37 UTC
Message-ID
<20071113173721.GI25282@penguin.codegnome.org>

I've created some bash functions which handle tagging some files with revision information, but even after reading the git manual I'm not really sure how to integrate them so that they remove revision expansion before each check-in (to avoid cluttering the repository with keyword substitutions), and add them back (with the current commit info) after each commit.

These are the functions:
    # Show some kind of useful revision string, like the RCS $Id$ string. I
    # think commit hash, filename, hostname containing the repository, and
    # timestamp should be plenty of information to track down a given file.
    git-id () {
	for file in "$@"; do
	    _date=$(date +'%F %T %Z')
	    git log -1 \
		--pretty=format:"[%h] \"$file\" $(hostname -f) ($_date)" \
		"$file"
	done
    }
    # Replace the $Id$ keyword string in the file itself.
    git-export () {
	for file in "$@"; do
	    echo Modifying $file...
	    _id=$(git-id "$file")
	    sed -ri 's/\$(Id|Revision).*\$/$Id: '"$_id"' $/' "$file"
	done
    }
    # Clean the $Id$ keyword string to prevent cluttering the repository
    # with keyword-revision diffs when we check the file back in.
    git-unexport () {
	for file in "$@"; do
	    echo Resetting $file...
	    sed -ri 's/\$Id.*\$/$Id$/' "$file"
	done
    }
How do I hook this in the way I want so that it's handled automatically?
-- 
"Oh, look: rocks!"
	-- Doctor Who, "Destiny of the Daleks"
Next: Jakub Narebski
Message 1 of 6 in “Integrating with hooks”
  1. Todd A. JacobsNov 13, 2007
  2. Jakub NarebskiNov 13, 2007
  3. Todd A. JacobsNov 15, 2007
  4. Jakub NarebskiNov 15, 2007
  5. Johannes SchindelinNov 15, 2007
  6. Johannes SixtNov 15, 2007

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.