我有一个post-checkout和后合并githook与这些内容:
#!/bin/bash
# MIT © Sindre Sorhus - sindresorhus.com
set -eux
changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
echo ''
echo 'running git submodule update --init --recursive if .gitmodules has changed'
check_run .gitmodules "git submodule update --init --recursive"
echo ''
echo 'running npm install if package.json has changed'
check_run package.json "npm prune && npm install"
echo ''
echo 'running npm build:localhost'
npm run build:localhost
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果.gitmodules没有更改,脚本将结束而不是检查package.json.(它甚至不执行第12行之后的回波线)
删除check_run调用并仅使用直接命令似乎工作正常.
删除check_run …