Git Hook under Windows

强颜欢笑 提交于 2019-12-20 09:39:53

问题


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?


回答1:


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




回答2:


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"



来源:https://stackoverflow.com/questions/22074247/git-hook-under-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!