0

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.

  • Does it have `~` (the home directory) in the path? If yes, change it to the real home path. – ElpieKay May 04 '18 at 12:30
  • @ElpieKay Thanks for the quick reply, but no the path is the full path from the C drive. – ToastedToast May 04 '18 at 12:32
  • If you run this command, manually, does it work? You say "C drive" and that opens up all sorts of "windows paths with spaces and backslashes" possibilities for errors. Also, it's always good practice to quote variables, e.g. `git --work-tree="$WRK_DIR" --git-dir="$GIT_DIR" checkout -f` in case they have spaces and other things in them. – Mort May 04 '18 at 13:55
  • @Mort Thanks for the input but I've since managed to solve the issue. 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. – ToastedToast May 04 '18 at 14:38
  • I'm not sure why you're trying to do this in the first place. Instead of pushing to production, why not just pull from origin as a deployment step? Then you wouldn't need a hook, if you make a non-bare repository. – Robin Green May 04 '18 at 17:27

1 Answers1

2

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.

Community
  • 1
  • 1