【发布时间】:2019-09-26 11:14:15
【问题描述】:
我在makefile 中有一个用于准备存储库的配方,它将所有.sh 文件转换为可执行文件。
在 Ubuntu 18.04 中,以下makefile
SHELL:=/bin/bash
prepare_repo:
pip install flake8==3.6.0
rm -f .git/hooks/pre-commit
flake8 --install-hook git
git config --bool flake8.strict true
sed '/__main__/r'<(\
echo -e " import subprocess\n\
subprocess.check_call(\"find . -name '*.sh' \n\
-exec sh -c ' \n\
for f do \n\
git check-ignore -q '$f'|| \n\
printf '%s\\\n' '$f' \n\
done \n\
' find-sh {} + | xargs git update-index --chmod=+x\", shell=True)"\
) -i -- .git/hooks/pre-commit
我加入了pre-commit 事件,因为我想将所有不在.gitignore 文件中的.sh 文件转换为可执行文件。
但问题是,如果我进入.git/hooks/pre-commit,我会找到以下代码
#!/home/fadi/anaconda3/bin/python
import sys
from flake8.main import git
if __name__ == '__main__':
import subprocess
subprocess.check_call("find . -name '*.sh'
-exec sh -c '
for f do
git check-ignore -q ''||
printf '%s\n' ''
done
' find-sh {} + | xargs git update-index --chmod=+x", shell=True)
sys.exit(
git.hook(
strict=git.config_for('strict'),
lazy=git.config_for('lazy'),
)
)
请注意这段代码是如何对$ 进行转义的。
git check-ignore -q ''||
printf '%s\n' ''
【问题讨论】: