15

I have the following code to checkout in a working directory in the hook post-receive:

#!/bin/sh
git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f

Unfortunately it doesn't seem to work. However, the command does work when I enter just this in the windows command line (cms):

git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f

I have checked the permissions and the executing attributes but nothing.

UPDATE:

I think I'm getting closer. Now I know what the problem is but I don't know why is this happening. The hook is actually being triggered but I receive this message:

remote: Starting copy from repository to work tree...
remote: fatal: Not a git repository: 'd:/_gitrepo.git/'
remote: Finished.

I have tried to change the path of d: to the whole network path but it still doesn't work. If I go to the remote repository and I do a git log, the changes are there and if I run the hook with sh, it works. Why is it saying that it is not a git repository when clearly it is?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Ramzendo
  • 576
  • 1
  • 5
  • 16

2 Answers2

16

I finally got it working! This is really weird. I had to type a pwd to see where actually is the batch being located and it showed the hook location on the server. However, in the next line I added a hostname and it showed me my local hostname. Then I add the whole path just like:

#!/bin/sh
echo "Starting copy from repository to work tree..."
pwd
hostname
git --work-tree=//remotehost/d$/Webseiten/__gitweb --git-dir=//remotehost/d$/_gitr
epo.git checkout -f
echo "Finished."

I hope this solution works for someone

Ramzendo
  • 576
  • 1
  • 5
  • 16
  • I had the same problem - then realized because my remote repo was added with a file system path (\\server\path) the hooks on the remote didn't execute on the remote machine. Looking into http://bonobogitserver.com/ to set up remote git server. – Philip Holly Dec 08 '14 at 14:48
4

For a shell script (and those hook scripts will be executed as shell, even in Windows, through the msys layer of msysgit), you could use a different sort of path:

#!/bin/sh
git --work-tree=/d/websites/__gitweb --git-dir=/d/_gitrepo.git/ checkout -f

See also other possibilities with "Posix path conversion in MinGW"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Hi! I tried that already and if I type in the Git Bash `sh post-receive` and it works. But the problem is that the script doesn't seem to trigger. – Ramzendo Feb 28 '14 at 08:19