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

Re: How to bypass the post-commit hook?

From
JHJan Hudec <bulb@ucw.cz>
Date
Dec 31, 2007, 10:55 UTC
Message-ID
<20071231105514.GA9214@efreet.light.src>
In-Reply-To
<46dff0320712310222m64d86e95l1499a7ffb1fff65c@mail.gmail.com>
On Mon, Dec 31, 2007 at 18:22:37 +0800, Ping Yin wrote:
Show 28 quoted lines
> On Dec 31, 2007 5:31 PM, Jan Hudec <bulb@ucw.cz> wrote:
> > On Mon, Dec 31, 2007 at 13:08:05 +0800, Ping Yin wrote:
> > > On Dec 31, 2007 5:50 AM, Jan Hudec <bulb@ucw.cz> wrote:
> > Well, I guess noone thought it would be useful to disable it.
> >
> > > I use post-commit because i don't find a better way to update imported
> > > css version automatically
> > >
> > > $ cat foo.css
> > > @import url(bar.css?57e708)
> > > ...
> > >
> > > When i modify bar.css and then commit it ( with blob sha1 bf7059),I
> > > use post-commit to modify foo.css
> > > $ cat foo.css
> > > @import url(bar.css?bf7059)
> > > ...
> >
> > But that file is not versioned, is it?
> >
> No, bar.css is also versioned
> 
> > Because if it is, you want to commit it in the very same commit as bar.css
> > and therefore want to do it in the *pre*-commit hook. Since obviously the
> > foo.css wants to include the current version of bar.css, not the previous
> > one.
> 
> If this happens, i have to commit twice (the last is amend)

Therefore the refered commit is dropped on the floor and will be eventually expired. So using commit id of an amended commit was an error.

Show 7 quoted lines
> > Note, that while you don't know the commit sha1 before the commit, you do
> > know the *blob* sha1s. So you can do this change in pre-commit hook.
> 
> I chose post-commit because i used commit sha1 instead of blob sha1 as
> file version in the first time, and now pre-commit seems better. One
> more question,  I use 'git ls-files' to fetch the blob sha1, so is the
> got sha1  the same when pre-commit and post-commit?
Yes, it should be.

Commit might be preparing the index to commit under different name than default, but it will export GIT_INDEX_FILE environment variable to the pre-commit hook and git commands you call will know to take the index from there.

Note, that you can -- and should -- add the foo.css to the commit. But the file might contain other changes in tree, that are not about to be commited, so prefered way would be to get the content from the index, modify that and update the index manually (with git update-index).

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
Previous: Jan HudecNext: Ping Yin
Message 6 of 9 in “How to bypass the post-commit hook?”
  1. Ping YinDec 30, 2007
  2. Jan HudecDec 30, 2007
  3. Pascal ObryDec 31, 2007
  4. Jan HudecJan 14, 2008
  5. Jan HudecDec 31, 2007
  6. Jan HudecDec 31, 2007
  7. Ping YinDec 31, 2007
  8. Jan HudecDec 31, 2007
  9. Ping YinDec 31, 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.