Git-Hook post_commit没有将GIT_DIR环境打印到日志中。

问题描述 投票:0回答:1

调试git-hooks

为什么是 $GIT_DIR 没有打印到日志中?

#Content of githookTest.sh 
foo=~/tmp/foo 
rm -rf $foo
mkdir -p $foo
cd $foo 
git init 
printf "logger 'foo was committed from:' $GIT_DIR" >> .git/hooks/post-commit
sudo chmod +x .git/hooks/post-commit  
touch $foo/bar
git add .
git commit -m "Testmessage"
journalctl -b --grep 'foo was committed from:'

上层脚本的输出

Initialized empty Git repository in /home/user/tmp/foo/.git/
[master (root-commit) 6c16412] Testmessage
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
-- Logs begin at Sat 2019-06-29 11:02:45 CEST, end at Mon 2020-05-04 09:53:18 CEST. --
May 04 09:53:18 x user[5892]: foo was committed from:
githooks
1个回答
0
投票

添加

export GIT_DIR=${GIT_DIR-`git rev-parse --git-dir`}

为首 post-commit 一语中的

© www.soinside.com 2019 - 2024. All rights reserved.