remote: handle rename of remote without fetch refspec
commit5a97b3810946440764a0a9a2292fcfdfa11391d5
authorJeff King <peff@peff.net>
Thu, 22 Sep 2022 05:33:29 +0000 (22 01:33 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Sep 2022 19:59:52 +0000 (22 12:59 -0700)
treeeb5070ccfa30ab222223296a5a2f3cead1ffb51b
parenta0feb8611d4c0b2b5d954efe4e98207f62223436
remote: handle rename of remote without fetch refspec

We return an error when trying to rename a remote that has no fetch
refspec:

  $ git config --unset-all remote.origin.fetch
  $ git remote rename origin foo
  fatal: could not unset 'remote.foo.fetch'

To make things even more confusing, we actually _do_ complete the config
modification, via git_config_rename_section(). After that we try to
rewrite the fetch refspec (to say refs/remotes/foo instead of origin).
But our call to git_config_set_multivar() to remove the existing entries
fails, since there aren't any, and it calls die().

We could fix this by using the "gently" form of the config call, and
checking the error code. But there is an even simpler fix: if we know
that there are no refspecs to rewrite, then we can skip that part
entirely.

Reported-by: John A. Leuenhagen <john@zlima12.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/remote.c
t/t5505-remote.sh