{"thread":{"id":"11430","subject":"How to bypass the post-commit hook?","startedAt":"2007-12-30T15:12:12Z","lastAt":"2008-01-14T17:59:51Z","messageCount":9,"participants":["Ping Yin","Jan Hudec","Pascal Obry"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64225","messageId":"46dff0320712300712l78c1cdaeya5fa105be01f6b74@mail.gmail.com","threadId":"11430","inReplyTo":null,"subject":"How to bypass the post-commit hook?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2007-12-30T15:12:12Z","receivedAt":"2007-12-30T15:12:12Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"--no-verify can bypass pre-commit hook? Then how to bypass post-commit hook?\n\nUsually I want post-commit take effect. However, in the middle of\ngit-rebase, i want to bypass post-commit when 'git-commit --amend'\nsince my post-commit hooks will modify the working directory and so\nmake following rebase troubesome.\n\n-- \nPing Yin\n"},{"id":"64240","messageId":"20071230215008.GB20098@efreet.light.src","threadId":"11430","inReplyTo":"46dff0320712300712l78c1cdaeya5fa105be01f6b74@mail.gmail.com","subject":"Re: How to bypass the post-commit hook?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-12-30T21:50:08Z","receivedAt":"2007-12-30T21:50:08Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Sun, Dec 30, 2007 at 23:12:12 +0800, Ping Yin wrote:\n> --no-verify can bypass pre-commit hook? Then how to bypass post-commit hook?\n> \n> Usually I want post-commit take effect. However, in the middle of\n> git-rebase, i want to bypass post-commit when 'git-commit --amend'\n> since my post-commit hooks will modify the working directory and so\n> make following rebase troubesome.\n\nThere does not seem to be an option to do it, but you can always temporarily\ndisable it (unset the executable permission on it).\n\nBy the way, what is your post-commit hook doing anyway? Modifying the work\ntree *after* a commit does not sound like a common thing to do.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"64255","messageId":"20071231093152.GC20098@efreet.light.src","threadId":"11430","inReplyTo":"46dff0320712302108i61f3b868obb93f89c1c24062c@mail.gmail.com","subject":"Re: How to bypass the post-commit hook?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-12-31T09:31:52Z","receivedAt":"2007-12-31T09:31:52Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Mon, Dec 31, 2007 at 13:08:05 +0800, Ping Yin wrote:\n> On Dec 31, 2007 5:50 AM, Jan Hudec <bulb@ucw.cz> wrote:\n> >\n> > On Sun, Dec 30, 2007 at 23:12:12 +0800, Ping Yin wrote:\n> > > --no-verify can bypass pre-commit hook? Then how to bypass post-commit hook?\n> > >\n> > > Usually I want post-commit take effect. However, in the middle of\n> > > git-rebase, i want to bypass post-commit when 'git-commit --amend'\n> > > since my post-commit hooks will modify the working directory and so\n> > > make following rebase troubesome.\n> >\n> > There does not seem to be an option to do it, but you can always temporarily\n> > disable it (unset the executable permission on it).\n> >\n> > By the way, what is your post-commit hook doing anyway? Modifying the work\n> > tree *after* a commit does not sound like a common thing to do.\n> >\n> I have already considered disabling hook temporarily, but it is a\n> little annoying.\n\nWell, I guess noone thought it would be useful to disable it.\n\n> I use post-commit because i don't find a better way to update imported\n> css version automatically\n> \n> $ cat foo.css\n> @import url(bar.css?57e708)\n> ...\n> \n> When i modify bar.css and then commit it ( with blob sha1 bf7059)，I\n> use post-commit to modify foo.css\n> $ cat foo.css\n> @import url(bar.css?bf7059)\n> ...\n\nBut that file is not versioned, is it?\n\nBecause if it is, you want to commit it in the very same commit as bar.css\nand therefore want to do it in the *pre*-commit hook. Since obviously the\nfoo.css wants to include the current version of bar.css, not the previous\none.\n\nNote, that while you don't know the commit sha1 before the commit, you do\nknow the *blob* sha1s. So you can do this change in pre-commit hook.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"64559","messageId":"4778BB63.6080908@obry.net","threadId":"11430","inReplyTo":"20071230215008.GB20098@efreet.light.src","subject":"Re: How to bypass the post-commit hook?","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2007-12-31T09:50:27Z","receivedAt":"2007-12-31T09:50:27Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"Jan Hudec a écrit :\n> By the way, what is your post-commit hook doing anyway? Modifying the work\n> tree *after* a commit does not sound like a common thing to do.\n\nOr just trigger a build via a built robot or record a commit information\ninto an issue tracker...\n\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"64258","messageId":"20071231105514.GA9214@efreet.light.src","threadId":"11430","inReplyTo":"46dff0320712310222m64d86e95l1499a7ffb1fff65c@mail.gmail.com","subject":"Re: How to bypass the post-commit hook?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-12-31T10:55:14Z","receivedAt":"2007-12-31T10:55:14Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Mon, Dec 31, 2007 at 18:22:37 +0800, Ping Yin wrote:\n> On Dec 31, 2007 5:31 PM, Jan Hudec <bulb@ucw.cz> wrote:\n> > On Mon, Dec 31, 2007 at 13:08:05 +0800, Ping Yin wrote:\n> > > On Dec 31, 2007 5:50 AM, Jan Hudec <bulb@ucw.cz> wrote:\n> > Well, I guess noone thought it would be useful to disable it.\n> >\n> > > I use post-commit because i don't find a better way to update imported\n> > > css version automatically\n> > >\n> > > $ cat foo.css\n> > > @import url(bar.css?57e708)\n> > > ...\n> > >\n> > > When i modify bar.css and then commit it ( with blob sha1 bf7059)，I\n> > > use post-commit to modify foo.css\n> > > $ cat foo.css\n> > > @import url(bar.css?bf7059)\n> > > ...\n> >\n> > But that file is not versioned, is it?\n> >\n> No, bar.css is also versioned\n> \n> > Because if it is, you want to commit it in the very same commit as bar.css\n> > and therefore want to do it in the *pre*-commit hook. Since obviously the\n> > foo.css wants to include the current version of bar.css, not the previous\n> > one.\n> \n> If this happens, i have to commit twice (the last is amend)\n\nTherefore the refered commit is dropped on the floor and will be eventually\nexpired. So using commit id of an amended commit was an error.\n\n> > Note, that while you don't know the commit sha1 before the commit, you do\n> > know the *blob* sha1s. So you can do this change in pre-commit hook.\n> \n> I chose post-commit because i used commit sha1 instead of blob sha1 as\n> file version in the first time, and now pre-commit seems better. One\n> more question,  I use 'git ls-files' to fetch the blob sha1, so is the\n> got sha1  the same when pre-commit and post-commit?\n\nYes, it should be.\n\nCommit might be preparing the index to commit under different name than\ndefault, but it will export GIT_INDEX_FILE environment variable to the\npre-commit hook and git commands you call will know to take the index from\nthere.\n\nNote, that you can -- and should -- add the foo.css to the commit. But the\nfile might contain other changes in tree, that are not about to be commited,\nso prefered way would be to get the content from the index, modify that and\nupdate the index manually (with git update-index).\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"64263","messageId":"46dff0320712310526l2b801ed7xc52b7aae2d65048e@mail.gmail.com","threadId":"11430","inReplyTo":"20071231105514.GA9214@efreet.light.src","subject":"Re: How to bypass the post-commit hook?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2007-12-31T13:26:21Z","receivedAt":"2007-12-31T13:26:21Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Dec 31, 2007 6:55 PM, Jan Hudec <bulb@ucw.cz> wrote:\n> On Mon, Dec 31, 2007 at 18:22:37 +0800, Ping Yin wrote:\n> > On Dec 31, 2007 5:31 PM, Jan Hudec <bulb@ucw.cz> wrote:\n> > > On Mon, Dec 31, 2007 at 13:08:05 +0800, Ping Yin wrote:\n> > > Note, that while you don't know the commit sha1 before the commit, you do\n> > > know the *blob* sha1s. So you can do this change in pre-commit hook.\n> >\n> > I chose post-commit because i used commit sha1 instead of blob sha1 as\n> > file version in the first time, and now pre-commit seems better. One\n> > more question,  I use 'git ls-files' to fetch the blob sha1, so is the\n> > got sha1  the same when pre-commit and post-commit?\n>\n> Yes, it should be.\n>\n\nGood news. So pre-commit is actually the right choice.\n\n>\n> Note, that you can -- and should -- add the foo.css to the commit. But the\n> file might contain other changes in tree, that are not about to be commited,\n> so prefered way would be to get the content from the index, modify that and\n> update the index manually (with git update-index).\n\nIf pre-commit has modified files to be commited, it will abort this\ncommit and give a message to direct the user to commit again\nwith/without the changed content.\n\nAFAIK, git add -i can add selected chunk to the index. As you said,\ncan git-update-index also do this job?\n\n\n\n\n-- \nPing Yin\n"},{"id":"64266","messageId":"20071231170532.GB9214@efreet.light.src","threadId":"11430","inReplyTo":"46dff0320712310526l2b801ed7xc52b7aae2d65048e@mail.gmail.com","subject":"Re: How to bypass the post-commit hook?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-12-31T17:05:32Z","receivedAt":"2007-12-31T17:05:32Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Mon, Dec 31, 2007 at 21:26:21 +0800, Ping Yin wrote:\n> On Dec 31, 2007 6:55 PM, Jan Hudec <bulb@ucw.cz> wrote:\n> > Note, that you can -- and should -- add the foo.css to the commit. But the\n> > file might contain other changes in tree, that are not about to be commited,\n> > so prefered way would be to get the content from the index, modify that and\n> > update the index manually (with git update-index).\n> \n> If pre-commit has modified files to be commited, it will abort this\n> commit and give a message to direct the user to commit again\n> with/without the changed content.\n> \n> AFAIK, git add -i can add selected chunk to the index. As you said,\n> can git-update-index also do this job?\n\ngit update-index is the underlying plumbing for git add/git rm.\n\nHowever, you should change foo.css in index even if the working tree copy\ndoes not match it and is not selected for commit. Only way I see to do that\nis to prepare a patch and apply it to both the working tree (git apply) and\nto the index (git apply --cached).\n\nIt will probably work for you without such finesse, you will just have to be\naware of it's quirks.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"64271","messageId":"46dff0320712310953x13668223iafed07f7d912e6f3@mail.gmail.com","threadId":"11430","inReplyTo":"20071231170532.GB9214@efreet.light.src","subject":"Re: How to bypass the post-commit hook?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2007-12-31T17:53:48Z","receivedAt":"2007-12-31T17:53:48Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Jan 1, 2008 1:05 AM, Jan Hudec <bulb@ucw.cz> wrote:\n> On Mon, Dec 31, 2007 at 21:26:21 +0800, Ping Yin wrote:\n> > On Dec 31, 2007 6:55 PM, Jan Hudec <bulb@ucw.cz> wrote:\n> > > Note, that you can -- and should -- add the foo.css to the commit. But the\n> > > file might contain other changes in tree, that are not about to be commited,\n> > > so prefered way would be to get the content from the index, modify that and\n> > > update the index manually (with git update-index).\n> >\n> > If pre-commit has modified files to be commited, it will abort this\n> > commit and give a message to direct the user to commit again\n> > with/without the changed content.\n> >\n> > AFAIK, git add -i can add selected chunk to the index. As you said,\n> > can git-update-index also do this job?\n>\n> git update-index is the underlying plumbing for git add/git rm.\n>\n> However, you should change foo.css in index even if the working tree copy\n> does not match it and is not selected for commit. Only way I see to do that\n> is to prepare a patch and apply it to both the working tree (git apply) and\n> to the index (git apply --cached).\n>\nA little complicated-:). So my way is to abort the commit if\npre-commit actually modified the files ( the working tree, not the\nindex) to be commited, then 'git add -i'  to add the changes\nintroduced just by the pre-commit and 'git commit' again.\n\n\n\n-- \nPing Yin\n"},{"id":"65326","messageId":"20080114175951.GA5527@efreet.light.src","threadId":"11430","inReplyTo":"4778BB63.6080908@obry.net","subject":"Re: How to bypass the post-commit hook?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2008-01-14T17:59:51Z","receivedAt":"2008-01-14T17:59:51Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Mon, Dec 31, 2007 at 10:50:27 +0100, Pascal Obry wrote:\n> Jan Hudec a écrit :\n> > By the way, what is your post-commit hook doing anyway? Modifying the work\n> > tree *after* a commit does not sound like a common thing to do.\n> \n> Or just trigger a build via a built robot or record a commit information\n> into an issue tracker...\n\nThat's not a case of \"modifying a work tree *after* a commit\".\n\nThere are many valid uses for post-commit hook and this is one of them. But\nlike the others it does not modify versioned files. That was the issue\ndiscussed (and pre-commit indeed turned out a better match).\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"}]}