我創建了一個非常簡單的預提交腳本: -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