簡體   English   中英

GitKraken 忽略服務器端預接收掛鈎?

[英]GitKraken ignoring server-side pre-receive hooks?

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顯示我們成功拒絕了推送。

但是,如果我現在在 GitKraken 中打開repo ,我可以簡單地單擊“推送”,告訴它使用默認的 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

我在GitKraken 的 Slack 頻道上問了這個問題並得到了答案

GitKraken 實際上並沒有在底層使用 Git,而只是遵循其協議。

長話短說,如果服務器是遠程的,服務器端的鈎子將與 GitKraken 一起工作(在這種情況下,服務器的 Git 會自然地調用鈎子)。 但是,由於我的示例(和實際案例)使用本地服務器,GitKraken 管理整個交互。 不幸的是,GitKraken 的“Git implementation”沒有服務器端的鈎子。

因此,本地服務器上的 GitKraken 意味着沒有服務器端掛鈎。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM