简体   繁体   中英

GitKraken ignoring server-side pre-receive hooks?

Does GitKraken bypass server-side pre-receive hooks?

I have a commit I want to push to the server.

However (for testing purposes), I've set a trivial pre-receive hook on the server which rejects any and all pushes and creates a file (as a signal the hook's running):

#!/bin/bash

echo tests > $PWD/../x.txt
exit 1

If I use Git Bash (for Windows), my push obviously gets rejected, but file x.txt is created out of the server repo:

$ git push
[...]
To server/repo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'server/repo.git'

However, if I perform the push via GitKraken, the push goes through, and x.txt is not created! Running git log on the server confirms that the push went through, so GitKraken isn't lying.

How's this possible? These hooks aren't shown on the relevant GitKraken support page , but I assume that's because those are all local hooks ( pre-commit/rebase , etc). I can't understand how it gets the server to ignore its own hooks...

As a reproducible example, in 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

The remote: Nope! and presence of x.txt mean the hook was called and the git log shows we successfully rejected the push.

However, if I now open repo in GitKraken, I can simply click "Push", tell it to use the default origin/master branch, and get the notification "Push Successful: master to origin".

Confirming the push truly went through with Git Bash:

cd ../repo.git
git log
# Author: Wasabi <wasabi@email.local>
# Date:   Mon Oct 14 15:00:49 2019 -0300
# 
#     test

I asked this question on GitKraken's Slack channel and got my answer :

GitKraken doesn't actually use Git under the hood, but simply follows its protocols.

Long story short, server-side hooks would work with GitKraken if the server were remote (in which case the server's Git would naturally call the hooks). However, since my example (and real-world case) uses a local server, GitKraken manages the whole interaction. Unfortunately, GitKraken's "Git implementation" doesn't have server-side hooks.

So, GitKraken on a local server means no server-side hooks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM