Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2020-10-27 12:41:36 +0300
committerJunio C Hamano <gitster@pobox.com>2020-10-27 21:40:33 +0300
commit9144ba4cf52bb0e891d7c10a331fc32c1d3e8f64 (patch)
tree5ca271ed926731c68c5a72fd323feeafe3d19bd9 /t/t5505-remote.sh
parent2e673356aefa8ed19be3c878f966ad6189ecb510 (diff)
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>
Diffstat (limited to 't/t5505-remote.sh')
-rwxr-xr-xt/t5505-remote.sh16
1 files changed, 8 insertions, 8 deletions
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 8d62edd98b..c99659d39e 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -145,8 +145,8 @@ test_expect_success 'remove remote protects local branches' '
test_expect_success 'remove errors out early when deleting non-existent branch' '
(
cd test &&
- echo "fatal: No such remote: '\''foo'\''" >expect &&
- test_must_fail git remote rm foo 2>actual &&
+ echo "error: No such remote: '\''foo'\''" >expect &&
+ test_expect_code 2 git remote rm foo 2>actual &&
test_i18ncmp expect actual
)
'
@@ -173,24 +173,24 @@ test_expect_success 'remove remote with a branch without configured merge' '
test_expect_success 'rename errors out early when deleting non-existent branch' '
(
cd test &&
- echo "fatal: No such remote: '\''foo'\''" >expect &&
- test_must_fail git remote rename foo bar 2>actual &&
+ echo "error: No such remote: '\''foo'\''" >expect &&
+ test_expect_code 2 git remote rename foo bar 2>actual &&
test_i18ncmp expect actual
)
'
test_expect_success 'add existing foreign_vcs remote' '
test_config remote.foo.vcs bar &&
- echo "fatal: remote foo already exists." >expect &&
- test_must_fail git remote add foo bar 2>actual &&
+ echo "error: remote foo already exists." >expect &&
+ test_expect_code 3 git remote add foo bar 2>actual &&
test_i18ncmp expect actual
'
test_expect_success 'add existing foreign_vcs remote' '
test_config remote.foo.vcs bar &&
test_config remote.bar.vcs bar &&
- echo "fatal: remote bar already exists." >expect &&
- test_must_fail git remote rename foo bar 2>actual &&
+ echo "error: remote bar already exists." >expect &&
+ test_expect_code 3 git remote rename foo bar 2>actual &&
test_i18ncmp expect actual
'