post-checkout git hook不工作

2ic8powd  于 2023-09-29  发布在  Git
关注(0)|答案(3)|浏览(192)

我有一个叫做post-checkout的git checkout钩子

  1. $ ll /usr/local/Cellar/git/2.3.5/share/git-core/templates/hooks/post-checkout
  2. -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

结帐后的内容为:

  1. #!/usr/bin/env bash
  2. echo "Hello from post-checkout"
  3. # Delete .pyc files and empty directories from root of project
  4. cd ./$(git rev-parse --show-cdup)
  5. # Clean-up
  6. find . -name ".DS_Store" -delete
  7. NUM_PYC_FILES=$( find . -name "*.pyc" | wc -l | tr -d ' ' )
  8. if [ $NUM_PYC_FILES -gt 0 ]; then
  9. find . -name "*.pyc" -delete
  10. printf "\e[00;31mDeleted $NUM_PYC_FILES .pyc files\e[00m\n"
  11. fi

所以当我克隆我的repo时,我将模板的路径传递给模板标志,如下所示:

  1. $ git clone https://[email protected]/sanfx/git-maildiff.git --template=/usr/local/Cellar/git/2.3.5/share/git-core/templates/

但是在我克隆并CD到git-maildiff的克隆目录并尝试 checkout 之后,我什么也没有得到。

  1. $ git clone https://[email protected]/sanfx/git-maildiff.git --template=/usr/local/Cellar/git/2.3.5/share/git-core/templates/
  2. Cloning into 'git-maildiff'...
  3. remote: Counting objects: 239, done.
  4. remote: Compressing objects: 100% (215/215), done.
  5. remote: Total 239 (delta 109), reused 0 (delta 0)
  6. Receiving objects: 100% (239/239), 72.90 KiB | 0 bytes/s, done.
  7. Resolving deltas: 100% (109/109), done.
  8. Checking connectivity... done.
  9. $ git checkout
  10. Your branch is up-to-date with 'origin/master'.

但是如果我运行我的可执行post-checkout分支,我会得到在shell中打印的Hello from post-checkout。
哪里出了问题?

vhipe2zx

vhipe2zx1#

根据文档后结帐脚本接收3个参数。我遇到了类似的问题,我解决了添加一行来读取这些参数(不使用它们并不重要)。该脚本将如下所示:

  1. #!/usr/bin/env bash
  2. read previousref newref flag
  3. echo "Hello from post-checkout"
  4. .....
v7pvogib

v7pvogib2#

我需要更新这个文件:

  1. <repo>/.git/hooks/post-checkout

而不是这个:

  1. <repo>/.githooks/post-checkout
am46iovg

am46iovg3#

确保您的post-checkout文件设置为可执行文件。否则Git会忽略它。

  1. chmod +x .git/hooks/post-checkout

相关问题