Git post-receive hook cannot return to original cwd

When clicking on our shared open repository (on top of ssh), the post commit does not work properly.
This is pretty common since I found a lot of threads here, and it works great for two other repositories on the same server, which drives me crazy.

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

The repository itself is located in the same directory as the directory to which the hook should be sent to

 /ab/cd/barerepo 

When clicked, it does not check the files for 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 on what this means. (Google only calls commit commit to git, if I can tell). So I read and guessed and tried ...

  • Additionally set GIT_DIR in the receiver after receiving.
  • reinitializing the main repo with - git -dir = / ab / cd / barerepo --working-dir = / ab / cd / staging
  • manual configuration of the working directory in the barerepo / config file
  • setting up an empty blank copy and commit
  • setting up a bare repo by cloning

Now the configuration looks like this:

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

but I also had it (effortless)

 [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 hook after taking

 echo "post-receive done" > updated.txt 

It writes the file to the open repository directory. This makes sense to me, as GIT_DIR seems to be set to ".", As evidenced by the post-receive message I received 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 return to the original cwd (current working directory?)? FYI: I'm still pretty new to git, and I have a dumb feeling that I'm missing something obvious, but not finding anything significant in this particular error message, makes me think. The push itself works great, by the way.

+8
git git-post-receive
source share
3 answers

After upgrading the server to git v1.7.5.4, the problem disappeared. It seems that the discrepancy from v1.5x (Server) to 1.7x (local) was too big.

+2
source share

I also ran into this problem for one out of ten site hosted on the same server.

Each site has a bare repo on a web server (not open on the Internet), which our developers apply to. Like you, we use git post-receive hook to then GIT_WORK_TREE=/whatever/livesite git checkout -f in the directory that contains the actual root of the web server.

After examining what looked like what failed with fatal: Could not jump back into original cwd , I saw that in all working cases the repository names were like this:

 /var/www/coolsite.com.git <-- bare repo /var/www/coolsite.com.live <-- checked out from hook; contains site root in public subdir 

One of the errors was this:

 /var/www/brokensite.com.git <-- bare repo /var/www/brokensite.com <-- checked out from hook; contains site root in public subdir 

Thus, if you checked the extract from the original copy, you would get a name that would call git to throw this error. Changing the real-time working repository name to work with ".wtf" fixed the problem (I ended up using .live, like the others).

In my case, the git server version is 1.6.1, and the dev machines are 1.7.5.4.

So the name of the bare repo and the real repo is similar to the result. Not sure if this is a bug in git or just a side effect of some magic equivalence of "foo" and "foo.git".

+17
source share

From my experience, your problem is that you have a .git repository and a working tree directory (to which your hook is checked after receiving) in the same directory: ab / cd.

I am new to GIT and this post really helped me, so thanks! Excluding all the corrections that you have already tried, I came across a message somewhere (I'm afraid I can’t find it now) that read the .git repository, and the working tree directory cannot be in the same directory.

I do not know why.

So, for example, you have a directory / staging / in your / var / www. This would mean that you should host your bare .git repository in / var / GIT (or something else), and not / var / www.

Another issue I ran into was permissions, so I chowned and chmod'ed both directories to ensure that the remote user I was pushing had read / write permission to both directories.

Anyway, I did this, and I realized where you came from:

 Counting objects: 3357, done. Delta compression using up to 8 threads. Compressing objects: 100% (2848/2848), done. Writing objects: 100% (3057/3057), 15.20 MiB | 4.70 MiB/s, done. Total 3057 (delta 1536), reused 0 (delta 0) Checking out files: 100% (3720/3720), done. To ssh://xxxxxx@xxxxxxxxxxxxxxx/var/GIT/project.git 945fe94..dbe1f0b master -> master 

This is a good fat check full of code :)

+6
source share

All Articles