我有git checkout hook称为post-checkout
$ ll /usr/local/Cellar/git/2.3.5/share/git-core/templates/hooks/post-checkout
-rwxr-xr-x 1 root wheel 375 Aug 13 14:11 /usr/local/Cellar/git/2.3.5/share/git-core/templates/hooks/post-checkout
结账后的内容是:
#!/usr/bin/env bash
echo "Hello from post-checkout"
# Delete .pyc files and empty directories from root of project
cd ./$(git rev-parse --show-cdup)
# Clean-up
find . -name ".DS_Store" -delete
NUM_PYC_FILES=$( find . -name "*.pyc" | wc -l | tr -d ' ' )
if [ $NUM_PYC_FILES -gt 0 ]; then
find . -name "*.pyc" -delete
printf "\e[00;31mDeleted $NUM_PYC_FILES .pyc files\e[00m\n"
fi
所以,当我克隆我的回购时,我将模板的路径传递给模板标志,如下所示:
$ git clone https://[email protected]/sanfx/git-maildiff.git --template=/usr/local/Cellar/git/2.3.5/share/git-core/templates/
但在克隆和CD到git-maildiff的克隆目录之后,我尝试结帐,我什么都没得到。
$ git clone https://[email protected]/sanfx/git-maildiff.git --template=/usr/local/Cellar/git/2.3.5/share/git-core/templates/
Cloning into 'git-maildiff'...
remote: Counting objects: 239, done.
remote: Compressing objects: 100% (215/215), done.
remote: Total 239 (delta 109), reused 0 (delta 0)
Receiving objects: 100% (239/239), 72.90 KiB | 0 bytes/s, done.
Resolving deltas: 100% (109/109), done.
Checking connectivity... done.
$ git checkout
Your branch is up-to-date with 'origin/master'.
但是,如果我运行我的可执行文章post-checkout分支,我会在shell中打印出来的post-checkout。
那么在哪里出错了?
根据documentation post-checkout脚本收到3个参数。我有一个类似的问题,我解决了添加一行来读取这些参数(它们没有被使用并不重要)。该脚本将如下所示:
#!/usr/bin/env bash
read previousref newref flag
echo "Hello from post-checkout"
.....