From fb86e32dcc9ed07ee2f1df6aafbf34d469007b1f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 23 Dec 2014 14:25:05 +0100 Subject: [PATCH 1/2] git remote: allow adding remotes agreeing with url.<...>.insteadOf 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 Signed-off-by: Junio C Hamano --- builtin/remote.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/remote.c b/builtin/remote.c index 46ecfd9f7b..b4ff468977 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -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); From b90c95d90ed9e96a0c1515c00fa8c0f92a0cb130 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 23 Dec 2014 14:25:09 +0100 Subject: [PATCH 2/2] Add a regression test for 'git remote add ' Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t5505-remote.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index ac79dd915d..17c6330f98 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -1113,4 +1113,9 @@ test_extra_arg set-url origin newurl oldurl # prune takes any number of args # update takes any number of args +test_expect_success 'add remote matching the "insteadOf" URL' ' + git config url.xyz@example.com.insteadOf backup && + git remote add backup xyz@example.com +' + test_done