'git push --atomic' doesn't report errors from our handlers
Gitlab-Shell is exiting with code 1 if the command errored. This may happen for example if one of Gitaly's RPC handlers return an error, for example for the receive-pack
command. If the command failed, one would expect to have an error printed out.
With non-atomic pushes, Git prints out the error and exits with non-zero code as expected when gitlab-shell
exits with non-zero code:
❯ git push origin main
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 181 bytes | 181.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
To ssh://localhost:2222/root/test-project-1.git
6b0a2ab..82e4baa main -> main
error: failed to push some refs to 'ssh://localhost:2222/root/test-project-1.git'
However, the error doesn't get printed out when the push is done with --atomic
, and git exits with code 0 indicating success. The below call has actually errored out even though the output doesn't show it in anyway:
❯ git push origin main --atomic
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 181 bytes | 181.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
To ssh://localhost:2222/root/test-project-1.git
6b0a2ab..82e4baa main -> main
This appears to be a bug in git as it is explicitly ignoring the exit code of the command with --atomic
. The commit that introduced this issue implies this is intentional, and the error should be checked elsewhere but the result is that the exit code is ignored and no error is displayed to the user.
This is confusing and the user would have no idea the operation has actually failed. If the status code of the error is not Internal
, we'd still print out our own error message in gitlab-shell.
❯ git push origin main --atomic
Pushing to ssh://localhost:2222/root/test-project-1.git
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 181 bytes | 181.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: ========================================================================
remote:
remote: ERROR: handler error
remote:
remote: ========================================================================
remote:
To ssh://localhost:2222/root/test-project-1.git
6b0a2ab..82e4baa main -> main
The push with --atomic
would still only display our custom error, not the final error line by Git and would exit with code 0 indicating success.
Here is a mailing list message with some more context about why we are ignoring errors coming from finish_connect()
https://lore.kernel.org/git/xmqqlfmtvqkh.fsf@gitster.c.googlers.com/
/cc @jcaigitlab might be something we want to fix as the users are told an operation succeeded even if it didn't.