Lee White
Lee White

Reputation: 3719

Not being able to pull in a git hook (bash script)

I am working on a website, on an Ubuntu 12.04 server. When I push code to my website, I want my hook to automatically pull the code in my apache folder. The following commands update my website to the repository's current master without any issues:

cd /var/www/www.foo.net
git pull

My post-update hook is what should automatically do this, but I keep getting the same error every time I to push. Note that the push is executing correctly every time. The script looks like this (irrelevant code left out):

#!/bin/bash
BRANCH=$(git rev-parse --symbolic --abbrev-ref $1)
case "$BRANCH" in
"somebranch")
        echo "You are pushing to somebranch!"
        cd /var/www/www.foo.net
        pwd
        git pull
        ;;
esac

In my opinion, this looks like it should work, especially considering that the debug output is what I am expecting it to be. Yet it does not work. I always get the following output:

remote: You are pushing to somebranch!
remote: /var/www/www.foo.net/
remote: fatal: Not a git repository: '.'

Note how it reports that it is in the correct directory and that, as I said above, I am able to pull in that directory without issue. /var/www/www.foo.net/ is a git repository.

I have also tried using ( cd /var/www/www.foo.net/ ; git pull ) but to no avail. I also don't think it can have anything to do with permissions; I am using Gitolite, and am able to pull to the local repository by using the account that's setup with Gitolite.

Any ideas? I'm having no joy at all.

Upvotes: 0

Views: 310

Answers (1)

forvaidya
forvaidya

Reputation: 3315

if /var/www/www.foo.net/ is a valid git repo try


git --git-dir=/var/www/www.foo.net/.git --work-tree=/var/www/www.foo.net pull 

This should result in FF pull.

Upvotes: 1

Related Questions