Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Hook under Windows

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?

like image 994
Ramzendo Avatar asked Feb 27 '14 16:02

Ramzendo


2 Answers

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

like image 192
Ramzendo Avatar answered Oct 09 '22 20:10

Ramzendo


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"

like image 37
VonC Avatar answered Oct 09 '22 18:10

VonC