Search code examples
gitgit-bashgithooksgit-post-receivegit-bare

Git hook/post-receive No such file or directory


So I've got a bare repository which we use to control the changes to our web pages. On that bare repo is a post-receive hook that runs when we push our changes to it. All the hook does is implement the changes to the working directory using the following code:

WRK_DIR="/url/to/work/tree/"
GIT_DIR="/url/to/bare/repo.git/"

#Update WRK_DIR with changes pushed into GIT_DIR...
git --work-tree=$WRK_DIR --git-dir=$GIT_DIR checkout -f

For whatever reason I receive the following:

remote: fatal: Not a git repository: '/url/to/bare/repo.git/'

I've verified that the hook is running under the correct user and that is has permissions to the folder. But for whatever reason the hook cannot find the directory and I am absolutely certain that the url's are correct.

Running

cd /url/to/bare/repo.git/

from within the hook is also returning

remote: hooks/post-receive: line 13: cd: /url/to/bare/repo.git/: No such file or directory

Like I said I am sure the url's are correct and that there are no typo's. Any help would be greatly appreciated.


Solution

  • Solved

    The hooks along with the bare repo were on the server so I placed some cd 's in the hook to test what it returned. Strangely it returned the contents of my local machine... have no idea why but if I change the variables to the network location of the folders and escape the backslashes it executes fine.