bachp/git-mirror

exit code when a git error occurs

mhow2 opened this issue · 2 comments

mhow2 commented

Hi,

This is by using git-mirror v0.14.1

In the following scenario with a GitLab group with 21 repositories, where git exits with code 1 for one of them, the tool still exits with exit code zero.

(...)
START 13/21 [2020-09-08 14:10:45.074225438 +02:00]: https://github.com/glpi-project/glpi.git -> git@gitlab.ow2.org:glpi/glpi.git
END(FAIL) 13/21 [2020-09-08 14:10:52.701738849 +02:00]: https://github.com/glpi-project/glpi.git -> git@gitlab.ow2.org:glpi/glpi.git (Command "git" "push" "--mirror" "git@gitlab.ow2.org:glpi/glpi.git" failed with exit code: 1, Stderr: To gitlab.ow2.org:glpi/glpi.git
 + 3c30649016...c4cff47b91 refs/pull/7874/merge -> refs/pull/7874/merge (forced update)
 ! [remote rejected]       stonebuzz/dev -> stonebuzz/dev (deny updating a hidden ref)
 ! [remote rejected]       teclib/prelude -> teclib/prelude (deny updating a hidden ref)
error: failed to push some refs to 'git@gitlab.ow2.org:glpi/glpi.git'
(...)
DONE [2020-09-08 14:11:00.800645576 +02:00]: 20/21

Looking at the exit status:

$ echo $?
0

In this case, I wonder if it would make sense to have an exit status of 1, or any other value known by advance (and documented) ? (or is it as is by design?).

In my (Python) code that wraps git-mirror, I only raise an error (and log stderr) if git-mirror's exit status is > 0 so in the end I don't get any error reported with the above scenario. Of course, another approach would be to simply look if we have something fed to stderr but still I wanted to share this question with you.

Regards

bachp commented

Git-mirror can already export reports in junit and prometheus format. Maybe one of these can help you.

I agree it would probably be best to exit with a non 0 error code if any sync fails.

rcfja commented

Non zero exit would help me and my CI/CD also