Git 钩子不在 Windows 上运行 [英] Git hook not running on windows

查看:50
本文介绍了Git 钩子不在 Windows 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用钩子,在简单地运行脚本时遇到了一些问题,因为我使用 git 提交.当从 bash 终端使用

I'm just getting started with hooks and have met some trouble with simply running the script, as I commit with git. The script works completely as intended when ran from bash terminal with the

bash pre-commit

命令.但是在使用 git 提交时它根本不会运行.

command. But it doesn't run at all when committing with git.

文件位于C:/path/to/my/project/.git/hooks/pre-commit,文件内容为:

The file is located at C:/path/to/my/project/.git/hooks/pre-commit, and the content of the file is:

#!/bin/bash

cd ../
cd ../
echo "pre-commit start"
if py -m unittest discover 2>&1 | grep -q "FAILED"; then
  echo "Test(s) FAILED"
  exit 1
fi
echo "pre-commit end"

我已经尝试在终端中运行 chmod 命令,正如其他帖子中所建议的那样,完全没有变化.

I have tried running the chmod command in terminal, as suggested in other posts, with no change at all.

chmod +x pre-commit

推荐答案

问题是,即使文件位于 C:/path/to/my/project/.git/hooks/pre-commit,我在那里已经测试过了,该文件在 C:/path/to/my/project/目录中运行.因此,两次调用cd ../"会导致脚本退出项目目录,这肯定造成了某种错误.

The issue was that even though the file was located at C:/path/to/my/project/.git/hooks/pre-commit, where I had tested it from, the file was running in the C:/path/to/my/project/ directory. Thus calling "cd ../" twice resulted in the script exiting the project directory, which must have created some sort of error.

这篇关于Git 钩子不在 Windows 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆