1

My directory structure is:

~/parent.git/.git/hooks/post-receive

The post-receive hook looks like:

#!/bin/sh
git checkout -f

When I push into parent.git, the script does not run. I can't figure out the problem, as every bit of the internet says this should work.

I chmod'd post-receive, so I know that is not the problem. Any help is much appreciated.

rockorager
  • 43
  • 4
  • If you are trying to refresh the checked out files after pushing to a non-bare repository, please see [“Why won't I see changes in the remote repo after "git push"?”](https://git.wiki.kernel.org/index.php/GitFaq#Why_won.27t_I_see_changes_in_the_remote_repo_after_.22git_push.22.3F) in the Git FAQ. It recommends a much safer [post-update script](http://utsl.gen.nz/git/post-update). The problem is likely due to the cwd being the the repository directory itself and having GIT_DIR set to the same path. Probably related: [SO question 5531309](http://stackoverflow.com/q/5531309/193688). – Chris Johnsen Apr 04 '11 at 04:20

2 Answers2

2

As Chris mentioned you seem to have the same problem as reset hard on git push

Specifically hooks run with CWD and GIT_DIR set to the .git directory. This results in the checkout command running in the .git dir and the normal error about that being overridden.

If you do an ls in the remote .git dir you should find a full checkout in there.

The easiest way around this is to specify GIT_WORK_TREE on the front of the checkout command:

GIT_WORK_TREE=/my/git/checkout git checkout -f

The script Chris linked (http://utsl.gen.nz/git/post-update) is supposed to take care of this and a few other potential issues.

Community
  • 1
  • 1
Gordon Wrigley
  • 11,015
  • 10
  • 48
  • 62
  • Dunno how this is historically but just now I tried it with git 2.0.0 and at least pre-commit runs with the `CWD` set to repo root. – Ilkka Jun 06 '14 at 09:33
1

If I had a guess, I'd say that the pushing user doesn't have permission to perform the checkout in that directory. What I'd suggest you do is to build the minimal working script and build from there. IE, instead of:

git checkout -f

Do:

echo "Got here" > /tmp/git_push_log

Then try:

echo "Got here" > pwd_test

To check your assumptions about what directory this is operating in and what permissions are required.

Stefan Mai
  • 23,367
  • 6
  • 55
  • 61