Using Git Inside a Git Hook

Using Git Inside a Git Hook can cause problems. In my previous post: "Signal 13 Problems with Git Hooks" I describe how we are trying to automatically merge certain types of branches into a branch that is designed to hold them all. Anyway, that means we want to run some git commands inside of the git hook. We change dirs into another directory where we have a clone of the repo and start telling git to merge some stuff and we get a bunch of

remote: fatal: Not a git repository: '.'
But if we run the exact same commands as the git user everything works fine. Huh. Eventually we got our linux guru over and he noticed that the environment under which the git user runs is totally different when inside a hook. Gitolite does a bunch of things to the env, but the one that was screwing us up was the setting of the GIT_DIR. After we figured that out, the solution was as easy as:

ENV.delete 'GIT_DIR'

in our ruby script that is triggered by the 'post-receive' hook. And now I must get back to the fun.

Comments

Long Ouyang said…
I spent a couple of very frustrated hours trying to figure this out - thanks!
Anonymous said…
This solved my problem. Thanks for posting it!
Anonymous said…
Sir,
How about if one is using Shell script?
Does same command ENV.delete 'GIT_DIR'

work in Shell Script also?

Thanks

Popular posts from this blog

What's a Good Flog Score?

SICP Wasn’t Written for You

Point Inside a Polygon in Ruby