git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] git remote add: allow re-adding remotes with the same URL

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 22, 2014, 17:06 UTC
Message-ID
<9c0c693efe68b1c0b080c14104bb6c5f7bf74097.1419267895.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1419267895.git.johannes.schindelin@gmx.de>

When adding a remote, we make sure that the remote does not exist already.

For convenience, we allow re-adding remotes with the same URLs. This also handles the case that there is an "[url ...] insteadOf" setting in the config.

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>
---
 builtin/remote.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 46ecfd9..9168c83 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -180,7 +180,8 @@ 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);
 
-- 
2.0.0.rc3.9669.g840d1f9
Previous: Johannes SchindelinNext: Junio C Hamano
Message 11 of 19 in “remote: allow adding remote w same name as alias”
  1. remote: allow adding remote w same name as aliasAnastas Dancha, Dec 16, 2014
  2. Johannes SchindelinDec 16, 2014
  3. Anastas DanchaDec 16, 2014
  4. Johannes SchindelinDec 19, 2014
  5. Anastas DanchaDec 19, 2014
  6. Michael J GruberDec 19, 2014
  7. Anastas DanchaDec 20, 2014
  8. Johannes SchindelinDec 21, 2014
  9. Michael J GruberDec 16, 2014
  10. 0/2 Let `git remote add` play nicer with url.<url>.insteadOfJohannes Schindelin, Dec 22, 2014
  11. 1/2 git remote add: allow re-adding remotes with the same URLJohannes Schindelin, Dec 22, 2014
  12. Junio C HamanoDec 22, 2014
  13. Johannes SchindelinDec 23, 2014
  14. 2/2 Add a regression test for 'git remote add <existing> <same-url>'Johannes Schindelin, Dec 22, 2014
  15. 0/2 Let `git remote add` play nicer with url.<url>.insteadOfJohannes Schindelin, Dec 23, 2014
  16. 1/2 git remote: allow adding remotes agreeing with url.<...>.insteadOfJohannes Schindelin, Dec 23, 2014
  17. 2/2 Add a regression test for 'git remote add <existing> <same-url>'Johannes Schindelin, Dec 23, 2014
  18. Johannes SchindelinDec 23, 2014
  19. Junio C HamanoDec 23, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.