Search code examples
gitgit-post-receive

git post-receive hook can not jump back into original cwd


When pushing to our shared bare repository (over ssh), the post-commit does not work properly.
It is pretty common as I found out in many threads here and it works fine for two other repositories on the same server, which drives me insane.

#!/bin/sh
GIT_WORK_TREE=/ab/cd/staging git checkout -f

The repository itself is in the same directory as the directory the hook shall checkout to

/ab/cd/barerepo

When pushing, it does not check out the files to the intended path, but gives this error message:

Writing objects: 100% (3/3), 299 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
fatal: Could not jump back into original cwd
error: hooks/post-receive exited with error code 128

I could not find any information about what this means. (Google only brings up commits from the contribution to git itself, as long as I can tell). So I read and guessed and tried …

  • additionally setting GIT_DIR in post-receive hook
  • re-initializing bare repo with --git-dir=/ab/cd/barerepo --working-dir=/ab/cd/staging
  • setting the working directory manually in barerepo/config
  • setting up the bare repo blank and committing
  • setting up the bare repo by cloning

Right now the config looks like this

[core]
     repositoryformatversion = 0
     filemode = true
     bare = true

but I also had this (to no effort)

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
    sharedrepository = 1
    worktree = /ab/cd/staging
    logallrefupdates = true
[receive]
    denyNonFastforwards = true

I also added a second line to the post-receive hook

echo "post-receive done" > updated.txt

It writes the file to the directory of the bare repository. This makes sense to me, since GIT_DIR seems to be set to '.', which is confirmed by a post-receive snipped I got from another SO question

echo Running $BASH_SOURCE
set | egrep GIT
echo PWD is $PWD

Result:

Running hooks/post-receive
GIT_DIR=.
PWD is /ab/cd/barerepo

So how can I bring git to jump back to the original cwd (current working directory?)? FYI: I'm still pretty new to git and have a dumb feeling that I'm missing something obvious, but not finding anything essential about this particular error message makes me wonder. The push itself works fine, btw.


Solution

  • After the server was updated to git v1.7.5.4 the problem was gone. Seems that the discrepancy from v1.5x (Server) to 1.7x (local) was too much.