Skip to content

ssh: Clean up output when pre-receive hook fails

Toon Claes requested to merge toon-fix-prerecv-noise into master

When the pre-receive hook failed, git-receive-pack(1) exits with code 0. It's arguable whether this is the expected behavior, but anyhow it means cmd.Wait() did not error out. On the other hand, the gitaly-hooks command did stop the transaction upon failure. So this final vote fails.

To avoid this error being presented to the end user, ignore it when the transaction was stopped.

Screenshots (sort of)

I tried to force push to main my local GDK, which is protected.

Before

$ git push origin HEAD --force-with-lease
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 344 bytes | 344.00 KiB/s, done.
Total 3 (delta 0), reused 2 (delta 0), pack-reused 0
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
remote: ERROR: rpc error: code = Aborted desc = final transactional vote: transaction was stopped
To gdk.test:root/yada.git
 ! [remote rejected] HEAD -> main (pre-receive hook declined)
error: failed to push some refs to 'gdk.test:root/yada.git'

After

$ git push origin HEAD --force-with-lease
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 344 bytes | 344.00 KiB/s, done.
Total 3 (delta 0), reused 2 (delta 0), pack-reused 0
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To gdk.test:root/yada.git
 ! [remote rejected] HEAD -> main (pre-receive hook declined)
error: failed to push some refs to 'gdk.test:root/yada.git'

Notice the remote: ERROR: rpc error: code = Aborted desc = final transactional vote: transaction was stopped line is not here.

Issue: #3636 (closed)

Edited by Toon Claes

Merge request reports

Loading