我有一个名为post-checkout的git checkout hook
$ 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://sanfx@bitbucket.org/sanfx/git-maildiff.git --template=/usr/local/Cellar/git/2.3.5/share/git-core/templates/
但是在克隆和CD到git-maildiff的克隆目录之后,我尝试结帐,我什么都没得到。
$ git clone https://sanfx@bitbucket.org/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'.
但是如果我运行我的可执行文章结帐后分支,我会在shell中打印出结帐后的Hello。
那么在哪里出错了?
答案 0 :(得分:0)
根据documentation post-checkout脚本收到3个参数。我有一个类似的问题,我决定添加一行来读取这些参数(它们并没有被使用)。该脚本将如下所示:
#!/usr/bin/env bash
read previousref newref flag
echo "Hello from post-checkout"
.....