threads / discuss / 11430

How to bypass the post-commit hook?

Subject: How to bypass the post-commit hook?

## tl;dr

9 messages between Dec 30, 2007 and Jan 14, 2008.

replies: 8people: 3as markdown or json

Ping Yin· Dec 30, 2007, 15:12 UTC · lore
--no-verify can bypass pre-commit hook? Then how to bypass post-commit hook?

Usually I want post-commit take effect. However, in the middle of git-rebase, i want to bypass post-commit when 'git-commit --amend' since my post-commit hooks will modify the working directory and so make following rebase troubesome.

-- 
Ping Yin
Jan Hudec· Dec 30, 2007, 21:50 UTC · re: Ping Yin · lore

Re: How to bypass the post-commit hook?

On Sun, Dec 30, 2007 at 23:12:12 +0800, Ping Yin wrote:
Show 6 quoted lines
> --no-verify can bypass pre-commit hook? Then how to bypass post-commit hook?
> 
> Usually I want post-commit take effect. However, in the middle of
> git-rebase, i want to bypass post-commit when 'git-commit --amend'
> since my post-commit hooks will modify the working directory and so
> make following rebase troubesome.

There does not seem to be an option to do it, but you can always temporarily disable it (unset the executable permission on it).

By the way, what is your post-commit hook doing anyway? Modifying the work tree *after* a commit does not sound like a common thing to do.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
Pascal Obry· Dec 31, 2007, 09:50 UTC · re: Jan Hudec · lore

Re: How to bypass the post-commit hook?

Jan Hudec a écrit :
> By the way, what is your post-commit hook doing anyway? Modifying the work
> tree *after* a commit does not sound like a common thing to do.

Or just trigger a build via a built robot or record a commit information into an issue tracker...

Pascal.
-- 
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
Jan Hudec· Jan 14, 2008, 17:59 UTC · re: Pascal Obry · lore

Re: How to bypass the post-commit hook?

On Mon, Dec 31, 2007 at 10:50:27 +0100, Pascal Obry wrote:
Show 6 quoted lines
> Jan Hudec a écrit :
> > By the way, what is your post-commit hook doing anyway? Modifying the work
> > tree *after* a commit does not sound like a common thing to do.
> 
> Or just trigger a build via a built robot or record a commit information
> into an issue tracker...
That's not a case of "modifying a work tree *after* a commit".

There are many valid uses for post-commit hook and this is one of them. But like the others it does not modify versioned files. That was the issue discussed (and pre-commit indeed turned out a better match).

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
Jan Hudec· Dec 31, 2007, 09:31 UTC · lore

Re: How to bypass the post-commit hook?

On Mon, Dec 31, 2007 at 13:08:05 +0800, Ping Yin wrote:
Show 18 quoted lines
> On Dec 31, 2007 5:50 AM, Jan Hudec <bulb@ucw.cz> wrote:
> >
> > On Sun, Dec 30, 2007 at 23:12:12 +0800, Ping Yin wrote:
> > > --no-verify can bypass pre-commit hook? Then how to bypass post-commit hook?
> > >
> > > Usually I want post-commit take effect. However, in the middle of
> > > git-rebase, i want to bypass post-commit when 'git-commit --amend'
> > > since my post-commit hooks will modify the working directory and so
> > > make following rebase troubesome.
> >
> > There does not seem to be an option to do it, but you can always temporarily
> > disable it (unset the executable permission on it).
> >
> > By the way, what is your post-commit hook doing anyway? Modifying the work
> > tree *after* a commit does not sound like a common thing to do.
> >
> I have already considered disabling hook temporarily, but it is a
> little annoying.
Well, I guess noone thought it would be useful to disable it.
Show 12 quoted lines
> 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?

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.

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.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
Jan Hudec· Dec 31, 2007, 10:55 UTC · lore

Re: How to bypass the post-commit hook?

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>
Ping Yin· Dec 31, 2007, 13:26 UTC · re: Jan Hudec · lore

Re: How to bypass the post-commit hook?

On Dec 31, 2007 6:55 PM, Jan Hudec <bulb@ucw.cz> wrote:
Show 13 quoted lines
> On Mon, Dec 31, 2007 at 18:22:37 +0800, Ping Yin wrote:
> > 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:
> > > 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.
>
Good news. So pre-commit is actually the right choice.
Show 5 quoted lines
>
> 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).

If pre-commit has modified files to be commited, it will abort this commit and give a message to direct the user to commit again with/without the changed content.

AFAIK, git add -i can add selected chunk to the index. As you said, can git-update-index also do this job?

-- 
Ping Yin
Jan Hudec· Dec 31, 2007, 17:05 UTC · re: Ping Yin · lore

Re: How to bypass the post-commit hook?

On Mon, Dec 31, 2007 at 21:26:21 +0800, Ping Yin wrote:
Show 12 quoted lines
> On Dec 31, 2007 6:55 PM, Jan Hudec <bulb@ucw.cz> wrote:
> > 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).
> 
> If pre-commit has modified files to be commited, it will abort this
> commit and give a message to direct the user to commit again
> with/without the changed content.
> 
> AFAIK, git add -i can add selected chunk to the index. As you said,
> can git-update-index also do this job?
git update-index is the underlying plumbing for git add/git rm.

However, you should change foo.css in index even if the working tree copy does not match it and is not selected for commit. Only way I see to do that is to prepare a patch and apply it to both the working tree (git apply) and to the index (git apply --cached).

It will probably work for you without such finesse, you will just have to be aware of it's quirks.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
Ping Yin· Dec 31, 2007, 17:53 UTC · re: Jan Hudec · lore

Re: How to bypass the post-commit hook?

On Jan 1, 2008 1:05 AM, Jan Hudec <bulb@ucw.cz> wrote:
Show 21 quoted lines
> On Mon, Dec 31, 2007 at 21:26:21 +0800, Ping Yin wrote:
> > On Dec 31, 2007 6:55 PM, Jan Hudec <bulb@ucw.cz> wrote:
> > > 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).
> >
> > If pre-commit has modified files to be commited, it will abort this
> > commit and give a message to direct the user to commit again
> > with/without the changed content.
> >
> > AFAIK, git add -i can add selected chunk to the index. As you said,
> > can git-update-index also do this job?
>
> git update-index is the underlying plumbing for git add/git rm.
>
> However, you should change foo.css in index even if the working tree copy
> does not match it and is not selected for commit. Only way I see to do that
> is to prepare a patch and apply it to both the working tree (git apply) and
> to the index (git apply --cached).
>

A little complicated-:). So my way is to abort the commit if pre-commit actually modified the files ( the working tree, not the index) to be commited, then 'git add -i' to add the changes introduced just by the pre-commit and 'git commit' again.

-- 
Ping Yin

← back to recent threads