builtin/remote: quote remote name on error to display empty name

When adding new remote name with empty string, git will print the following error message, fatal: '' is not a valid remote name\n But when removing remote name with empty string as input, git shows the empty string without quote, fatal: No such remote: \n To make these error messages consistent, quote the name of the remote that we tried and failed to find. Signed-off-by: Shulhan <m.shulhan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shulhan committed Sep 13, 2018 at 20:18 UTC 5025425dffffb4424b746de9209f874ab8b5d179
2 files changed +5 -5
builtin/remote.c
+3 -3
@@ -625,7 +625,7 @@ static int mv(int argc, const char **argv)
625
626 oldremote = remote_get(rename.old_name);
627 if (!remote_is_configured(oldremote, 1))
628 - die(_("No such remote: %s"), rename.old_name);
628 + die(_("No such remote: '%s'"), rename.old_name);
629
630 if (!strcmp(rename.old_name, rename.new_name) && oldremote->origin != REMOTE_CONFIG)
631 return migrate_file(oldremote);
@@ -761,7 +761,7 @@ static int rm(int argc, const char **argv)
761
762 remote = remote_get(argv[1]);
763 if (!remote_is_configured(remote, 1))
764 - die(_("No such remote: %s"), argv[1]);
764 + die(_("No such remote: '%s'"), argv[1]);
765
766 known_remotes.to_delete = remote;
767 for_each_remote(add_known_remote, &known_remotes);
@@ -860,7 +860,7 @@ static int get_remote_ref_states(const char *name,
860
861 states->remote = remote_get(name);
862 if (!states->remote)
863 - return error(_("No such remote: %s"), name);
863 + return error(_("No such remote: '%s'"), name);
864
865 read_branches();
866
t/t5505-remote.sh
+2 -2
@@ -145,7 +145,7 @@ test_expect_success 'remove remote protects local branches' '
145 test_expect_success 'remove errors out early when deleting non-existent branch' '
146 (
147 cd test &&
148 - echo "fatal: No such remote: foo" >expect &&
148 + echo "fatal: No such remote: '\''foo'\''" >expect &&
149 test_must_fail git remote rm foo 2>actual &&
150 test_i18ncmp expect actual
151 )
@@ -173,7 +173,7 @@ test_expect_success 'remove remote with a branch without configured merge' '
173 test_expect_success 'rename errors out early when deleting non-existent branch' '
174 (
175 cd test &&
176 - echo "fatal: No such remote: foo" >expect &&
176 + echo "fatal: No such remote: '\''foo'\''" >expect &&
177 test_must_fail git remote rename foo bar 2>actual &&
178 test_i18ncmp expect actual
179 )