Skip to content

Commit

Permalink
git remote: allow adding remotes agreeing with url.<...>.insteadOf
Browse files Browse the repository at this point in the history
When adding a remote, we make sure that the remote does not exist
already. However, this test was not quite correct: when the
url.<...>.insteadOf config variable was set to the remote name to be
added, the code would assume that the remote exists already.

Let's allow adding remotes when there is a url.<...>.insteadOf setting
when both the name and the URL agree with the remote to be added.

It might seem like a mistake to compare against remote->url[0] without
verifying that remote->url_nr >=1, but at this point a missing URL has
been filled by the name already, therefore url_nr cannot be zero.

Noticed by Anastas Dancha.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Dec 23, 2014
1 parent bbcefff commit fb86e32
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ static int add(int argc, const char **argv)
url = argv[1];

remote = remote_get(name);
if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||
if (remote && (remote->url_nr > 1 ||
(strcmp(name, remote->url[0]) &&
strcmp(url, remote->url[0])) ||
remote->fetch_refspec_nr))
die(_("remote %s already exists."), name);

Expand Down

0 comments on commit fb86e32

Please sign in to comment.