# What is the working directory for post-update hook?

4 messages from 2006-02-05 to 2006-02-05. Participants: Alan Chandler, Junio C Hamano.
Thread: https://gitlist.dev/t/3244

## Alan Chandler, 2006-02-05 09:06

Subject: What is the working directory for post-update hook?
Message-ID: <200602050906.52016.alan@chandlerfamily.org.uk>
URL: https://gitlist.dev/e/200602050906.52016.alan%40chandlerfamily.org.uk

```
The document root of my website has a git repository under it (in the 
standard .git subdirectory) and want a post update hook to checkout the 
contents (so the web server sees it!) 

I will be pushing to it via ssh.

Does this mean that the post-update hook with be run with a working directory 
of the web site's document root? or something relative (such as GIT_DIR) so 
that I don't have to do a specific cd to an absolute path.


-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

```

## Alan Chandler, 2006-02-05 09:37

Subject: Re: What is the working directory for post-update hook?
Message-ID: <200602050937.12885.alan@chandlerfamily.org.uk>
URL: https://gitlist.dev/e/200602050937.12885.alan%40chandlerfamily.org.uk
In-Reply-To: <200602050906.52016.alan@chandlerfamily.org.uk>

```
On Sunday 05 February 2006 09:06, Alan Chandler wrote:
> The document root of my website has a git repository under it (in the
> standard .git subdirectory) and want a post update hook to checkout the
> contents (so the web server sees it!)
>
> I will be pushing to it via ssh.
>
> Does this mean that the post-update hook with be run with a working
> directory of the web site's document root? or something relative (such as
> GIT_DIR) so that I don't have to do a specific cd to an absolute path.


I found it out, by getting the post update hook to e-mail me the value:-)

its in the repository (ie document_root/.git)

-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

```

## Junio C Hamano, 2006-02-05 09:41

Subject: Re: What is the working directory for post-update hook?
Message-ID: <7vd5i2kuqi.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vd5i2kuqi.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <200602050906.52016.alan@chandlerfamily.org.uk>

```
Alan Chandler <alan@chandlerfamily.org.uk> writes:

> The document root of my website has a git repository under it (in the 
> standard .git subdirectory) and want a post update hook to checkout the 
> contents (so the web server sees it!) 
>
> I will be pushing to it via ssh.
>
> Does this mean that the post-update hook with be run with a working directory 
> of the web site's document root? or something relative (such as GIT_DIR) so 
> that I don't have to do a specific cd to an absolute path.

The current implementation happens to chdir to GIT_DIR and sets
GIT_DIR=. in the environment, so if you have something like
this:

	/var/www/myproject/
	/var/www/myproject/.git/
	/var/www/myproject/.git/HEAD
	/var/www/myproject/.git/...
        /var/www/myproject/README

Then $(pwd) would be /var/www/myproject/.git/.  Your hook would
probably be able to do "cd .."  to get to the project top.

However, there is no guarantee for future implementations.

```

## Alan Chandler, 2006-02-05 10:58

Subject: Re: What is the working directory for post-update hook?
Message-ID: <200602051058.26570.alan@chandlerfamily.org.uk>
URL: https://gitlist.dev/e/200602051058.26570.alan%40chandlerfamily.org.uk
In-Reply-To: <7vd5i2kuqi.fsf@assigned-by-dhcp.cox.net>

```
On Sunday 05 February 2006 09:41, Junio C Hamano wrote:
> Alan Chandler <alan@chandlerfamily.org.uk> writes:
> > The document root of my website has a git repository under it (in the
> > standard .git subdirectory) and want a post update hook to checkout the
> > contents (so the web server sees it!)
> >
> > I will be pushing to it via ssh.
> >
> > Does this mean that the post-update hook with be run with a working
> > directory of the web site's document root? or something relative (such as
> > GIT_DIR) so that I don't have to do a specific cd to an absolute path.
>
> The current implementation happens to chdir to GIT_DIR and sets
> GIT_DIR=. in the environment, so if you have something like
> this:
>
> 	/var/www/myproject/
> 	/var/www/myproject/.git/
> 	/var/www/myproject/.git/HEAD
> 	/var/www/myproject/.git/...
>         /var/www/myproject/README
>
> Then $(pwd) would be /var/www/myproject/.git/.  Your hook would
> probably be able to do "cd .."  to get to the project top.
>

I did get it to work doing a cd .. - although you also have to unset GIT_DIR, 
because its is literally "." and not the directory that was "." at the time 
of setting, so a cd .. ; checkout -f then fails with an invalid repository.

-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

```
