【发布时间】:2017-11-09 06:05:25
【问题描述】:
大家好,我有一个 git repo,里面有 3 个文件夹(单个 js 项目)。
这是我的pre-commit 钩子
#!/bin/bash
echo -e "\033[1;92m Linting Staged Files . . . "
files=$(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$')
path=(${files[0]//// })
if [[ $files = "" ]] ; then
echo -e "\033[1;31m You have no staged file, exiting . . "
exit 1
fi
for file in $files
do
git show ":$file" | $("./$path/node_modules/.bin/eslint --stdin --stdin-filename $file")
if [ $? -ne 0 ]; then
echo -e "\033[1;31m ESLint failed on staged file '$file'. \n Code will not be committed, Please fix your code and try again."
exit 1
fi
done
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [[ "$BRANCH" == "master" || "$BRANCH" == "develop" ]]; then
echo "\033[1;31m commiting to $BRANCH is illegal."
echo "\033[1;31m If you really know what you're doing, then add the argument '-n' to skip this git hook."
exit 1
fi
exit 0
但它在这一行一直失败git show ":$file" | $("./$path/node_modules/.bin/eslint --stdin --stdin-filename $file")
有错误
.git/hooks/pre-commit: line 17: ./node_modules/.bin/eslint --stdin --stdin-filename sfa/src/SFAApp.js: No such file or directory
我不知道我做错了什么,请帮忙。
【问题讨论】:
标签: git bash githooks pre-commit-hook pre-commit