зеркало из https://github.com/microsoft/git.git
remote: actually check if remote exits
When converting the git remote command to a builtin in 211c89 ("Make git-remote a builtin"), a few calls to check if a remote exists were converted from: if (!exists $remote->{$name}) { [...] to: remote = remote_get(argv[1]); if (!remote) [...] The new check is not quite correct, because remote_get() never returns NULL if a name is given. This leaves us with the somewhat cryptic error message "error: Could not remove config section 'remote.test'", if we are trying to remove a remote that does not exist, or a similar error if we try to rename a remote. Use the remote_is_configured() function to check whether the remote actually exists, and die with a more sensible error message ("No such remote: $remotename") instead if it doesn't. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
674468b364
Коммит
cc8e538d45
|
@ -634,7 +634,7 @@ static int mv(int argc, const char **argv)
|
||||||
rename.remote_branches = &remote_branches;
|
rename.remote_branches = &remote_branches;
|
||||||
|
|
||||||
oldremote = remote_get(rename.old);
|
oldremote = remote_get(rename.old);
|
||||||
if (!oldremote)
|
if (!remote_is_configured(oldremote))
|
||||||
die(_("No such remote: %s"), rename.old);
|
die(_("No such remote: %s"), rename.old);
|
||||||
|
|
||||||
if (!strcmp(rename.old, rename.new) && oldremote->origin != REMOTE_CONFIG)
|
if (!strcmp(rename.old, rename.new) && oldremote->origin != REMOTE_CONFIG)
|
||||||
|
@ -773,7 +773,7 @@ static int rm(int argc, const char **argv)
|
||||||
usage_with_options(builtin_remote_rm_usage, options);
|
usage_with_options(builtin_remote_rm_usage, options);
|
||||||
|
|
||||||
remote = remote_get(argv[1]);
|
remote = remote_get(argv[1]);
|
||||||
if (!remote)
|
if (!remote_is_configured(remote))
|
||||||
die(_("No such remote: %s"), argv[1]);
|
die(_("No such remote: %s"), argv[1]);
|
||||||
|
|
||||||
known_remotes.to_delete = remote;
|
known_remotes.to_delete = remote;
|
||||||
|
|
|
@ -139,6 +139,24 @@ 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 &&
|
||||||
|
test_i18ncmp expect actual
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
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 &&
|
||||||
|
test_i18ncmp expect actual
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
cat >test/expect <<EOF
|
cat >test/expect <<EOF
|
||||||
* remote origin
|
* remote origin
|
||||||
Fetch URL: $(pwd)/one
|
Fetch URL: $(pwd)/one
|
||||||
|
|
Загрузка…
Ссылка в новой задаче