]> git.ipfire.org Git - thirdparty/git.git/commit
remote: add meaningful exit code on missing/existing
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 27 Oct 2020 09:41:36 +0000 (10:41 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Oct 2020 18:40:33 +0000 (11:40 -0700)
commit9144ba4cf52bb0e891d7c10a331fc32c1d3e8f64
tree5ca271ed926731c68c5a72fd323feeafe3d19bd9
parent2e673356aefa8ed19be3c878f966ad6189ecb510
remote: add meaningful exit code on missing/existing

Change the exit code for the likes of "git remote add/rename" to exit
with 2 if the remote in question doesn't exist, and 3 if it
does. Before we'd just die() and exit with the general 128 exit code.

This changes the output message from e.g.:

    fatal: remote origin already exists.

To:

    error: remote origin already exists.

Which I believe is a feature, since we generally use "fatal" for the
generic errors, and "error" for the more specific ones with a custom
exit code, but this part of the change may break code that already
relies on stderr parsing (not that we ever supported that...).

The motivation for this is a discussion around some code in GitLab's
gitaly which wanted to check this, and had to parse stderr to do so:
https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2695

It's worth noting as an aside that a method of checking this that
doesn't rely on that is to check with "git config" whether the value
in question does or doesn't exist. That introduces a TOCTOU race
condition, but on the other hand this code (e.g. "git remote add")
already has a TOCTOU race.

We go through the config.lock for the actual setting of the config,
but the pseudocode logic is:

    read_config();
    check_config_and_arg_sanity();
    save_config();

So e.g. if a sleep() is added right after the remote_is_configured()
check in add() we'll clobber remote.NAME.url, and add another (usually
duplicate) remote.NAME.fetch entry (and other values, depending on
invocation).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-remote.txt
builtin/remote.c
t/t5505-remote.sh