GitKraken 是否绕过服务器端预接收挂钩?
我有一个要推送到服务器的提交。
但是(出于测试目的),我pre-receive
在服务器上设置了一个简单的钩子,它拒绝任何和所有推送并创建一个文件(作为钩子运行的信号):
#!/bin/bash
echo tests > $PWD/../x.txt
exit 1
如果我使用 Git Bash(适用于 Windows),我的推送显然会被拒绝,但文件x.txt
是从服务器存储库中创建的:
$ git push
[...]
To server/repo.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'server/repo.git'
但是,如果我通过 GitKraken 执行推送,则推送会通过,并且x.txt
不会被创建!在服务器上运行git log
确认推送通过,所以 GitKraken 没有撒谎。
这怎么可能?这些钩子没有显示在相关的 GitKraken 支持页面上,但我认为那是因为这些都是本地钩子(pre-commit/rebase
等)。我不明白它如何让服务器忽略自己的钩子......
作为一个可重现的例子,在 Git Bash 中:
cd /testdir
mkdir repo.git
cd repo.git
git init --bare
# Initialized empty Git repository in /testdir/repo.git/
cat > hooks/pre-receive << EOF
#!/bin/bash
echo Nope!
echo x > ../x.txt
exit 1
EOF
cd ..
git clone repo.git
# Cloning into 'repo'...
# warning: You appear to have cloned an empty repository.
# done.
cd repo
touch .gitignore
git add .
git commit -m "test"
# [master (root-commit) e9b25d3] test
# Committer: Wasabi <wasabi@email.local>
# Your name and email address were configured [...]
# 1 file changed, 0 insertions(+), 0 deletions(-)
# create mode 100644 .gitignore
git push
# Enumerating objects: 3, done.
# Counting objects: 100% (3/3), done.
# Writing objects: 100% (3/3), 214 bytes | 53.00 KiB/s, done.
# Total 3 (delta 0), reused 0 (delta 0)
# remote: Nope! # shows the hook is working
# To testdir/repo.git
# ! [remote rejected] master -> master (pre-receive hook declined)
# error: failed to push some refs to 'testdir/repo.git'
ls ..
# repo/ repo.git/ x.txt
rm ../x.txt
# Confirming the push really didn't go through
cd ../repo.git
git log
# fatal: your current branch 'master' does not have any commits yet
和remote: Nope!
存在x.txt
意味着钩子被调用并且git log
我们成功地拒绝了推送。
但是,如果我现在repo
在 GitKraken 中打开,我可以简单地单击“推送”,告诉它使用默认的 origin/master 分支,并收到通知“推送成功:master to origin”。
使用 Git Bash 确认推送确实完成了:
cd ../repo.git
git log
# Author: Wasabi <wasabi@email.local>
# Date: Mon Oct 14 15:00:49 2019 -0300
#
# test