threads / discuss / 13730

post-receive hook

Subject: post-receive hook

## tl;dr

3 messages between May 30, 2008 and May 30, 2008.

replies: 2people: 2as markdown or json

david@lang.hm· May 30, 2008, 08:10 UTC · lore

I'm trying to setup a post-receive hook to do a checkout -f when I push to a public repo (it's a web based tool and I want the executables to be updated with a push)

unfortunantly if I just add git checkout -f to the post-receive hooks it checks the files out in the .git directory.

if I do a cd .. ; git checkout -f I get an error message complaining that it's not in a git repository, but if I manually cd to that directory and do a checkout it works.

what am I missing here?
David Lang
Johan Herland· May 30, 2008, 09:06 UTC · re: david@lang.hm · lore

Re: post-receive hook

On Friday 30 May 2008, david@lang.hm wrote:
Show 12 quoted lines
> I'm trying to setup a post-receive hook to do a checkout -f when I push to 
> a public repo (it's a web based tool and I want the executables to be 
> updated with a push)
> 
> unfortunantly if I just add git checkout -f to the post-receive hooks it 
> checks the files out in the .git directory.
> 
> if I do a cd .. ; git checkout -f I get an error message complaining that 
> it's not in a git repository, but if I manually cd to that directory and 
> do a checkout it works.
> 
> what am I missing here?
I'm guessing that the post-receive hook is invoked with "GIT_DIR=.", which goes bad the moment you chdir anywhere. I have this in my own update hook script:
if [ "$GIT_DIR" = "." ]; then
	GIT_DIR=`pwd`
fi
If you do this before the "cd .. ; git checkout -f", you might have better luck.
Have fun! :)
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
david@lang.hm· May 30, 2008, 09:43 UTC · re: Johan Herland · lore

Re: post-receive hook

On Fri, 30 May 2008, Johan Herland wrote:
Show 21 quoted lines
> On Friday 30 May 2008, david@lang.hm wrote:
>> I'm trying to setup a post-receive hook to do a checkout -f when I push to
>> a public repo (it's a web based tool and I want the executables to be
>> updated with a push)
>>
>> unfortunantly if I just add git checkout -f to the post-receive hooks it
>> checks the files out in the .git directory.
>>
>> if I do a cd .. ; git checkout -f I get an error message complaining that
>> it's not in a git repository, but if I manually cd to that directory and
>> do a checkout it works.
>>
>> what am I missing here?
>
> I'm guessing that the post-receive hook is invoked with "GIT_DIR=.", which goes bad the moment you chdir anywhere. I have this in my own update hook script:
>
> if [ "$GIT_DIR" = "." ]; then
> 	GIT_DIR=`pwd`
> fi
>
> If you do this before the "cd .. ; git checkout -f", you might have better luck.
thanks, that solved the problem.
David Lang

← back to recent threads