我创建了一个非常简单的预提交脚本: -Git的pre-commit钩子在GitHub上没有为Mac(适用于命令行)
#!/usr/bin/env sh
# Run tests
npm test
if [ $? -ne 0 ]; then
echo "Tests failed. Aborting.."
exit 1
fi
exit 0
当我在命令行中运行git commit
(未通过测试),我得到预期的出口1,并带有消息Tests failed. Aborting..
。
不过,如果我使用GitHub上的Mac,但是我得到:
.git/hooks/pre-commit: line 5: npm: command not found
Tests failed. Aborting..
(256)
我猜其打倒在不被提供到GitHub上为Mac使用的执行环境npm
,但我一直把我的头发撕掉试图找出如何解决这个问题。
“您可以通过添加” - 通过添加位置来确保/ usr/local/bin位于路径中? – sompylasar
@sompylasar在pre-commit脚本中,我发布了这个例子。我修改了问题中的脚本,并将其发布在我的答案中。它根据nvm是否可用来修改PATH – RustyToms