Git 预提交钩子在 GitHub for mac 中失败(在命令行上工作) [英] Git pre-commit hook failing in GitHub for mac (works on command line)
问题描述
我创建了一个非常简单的预提交脚本:-
I've created a very simple pre-commit script:-
#!/usr/bin/env sh
# Run tests
npm test
if [ $? -ne 0 ]; then
echo "Tests failed. Aborting.."
exit 1
fi
exit 0
<小时>
当我在命令行运行 git commit
时(测试失败),我得到预期的 exit 1,消息 Tests failed.正在中止..
.
When I run git commit
at the command line (with failing tests), I get the expected exit 1 with the message Tests failed. Aborting..
.
但是,如果我使用 GitHub for Mac 但是我得到:
However, If I use GitHub for Mac however I get:
.git/hooks/pre-commit: line 5: npm: command not found
Tests failed. Aborting..
(256)
我猜这是因为 npm
无法用于 GitHub for Mac 使用的执行环境,但我一直在努力研究如何解决这个问题.
I'm guessing its down to npm
not being available to the execution environment that GitHub for Mac is using, but I've been tearing my hair out trying to work out how to fix this.
推荐答案
已解决.由于全局安装的节点模块最终位于 /usr/local/bin
下,我只需要在预提交的开头添加以下内容:
Resolved. As globally installed node modules end up under /usr/local/bin
I simply needed to add the following at the beginning of my pre-commit:
PATH=$PATH:/usr/local/bin:/usr/local/sbin
即在执行点将 /usr/local/bin
和 /usr/local/sbin
附加到 PATH
.
i.e. appending both /usr/local/bin
and /usr/local/sbin
to PATH
at the point of execution.
这篇关于Git 预提交钩子在 GitHub for mac 中失败(在命令行上工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!