简体   繁体   English

Windows下的Git Hook

[英]Git Hook under Windows

I have the following code to checkout in a working directory in the hook post-receive: 我有以下代码在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): 但是,当我在Windows命令行(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. 我试图将d:的路径改为整个网络路径,但它仍然无效。 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. 如果我去远程存储库并且我做了一个git日志,那么更改就在那里,如果我用sh运行钩子,它就可以了。 Why is it saying that it is not a git repository when clearly it is? 为什么说它显然不是git存储库?

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. 我不得不键入一个pwd来查看批处理的实际位置,并显示服务器上的挂钩位置。 However, in the next line I added a hostname and it showed me my local hostname. 但是,在下一行中我添加了一个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 我希望这个解决方案适合某人

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: 对于shell脚本(并且这些钩子脚本将作为shell执行,即使在Windows中,也可以通过msysgit的msys层执行 ),您可以使用不同类型的路径:

#!/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 " 另请参见“ MinGW中Posix路径转换 ”的其他可能性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM