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

Re: [PATCH] remote: allow adding remote w same name as alias

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 16, 2014, 09:01 UTC
Message-ID
<alpine.DEB.1.00.1412160944180.13845@s15462909.onlinehome-server.info>
In-Reply-To
<20141216021900.50095.24877@random.io>
Hi Anastas,
On Tue, 16 Dec 2014, Anastas Dancha wrote:
Show 5 quoted lines
> When ~/.gitconfig contains an alias (i.e. myremote)
> and you are adding a new remote using the same name
> for remote, Git will refuse to add the remote with
> the same name as one of the aliases, even though the
> remote with such name is not setup for current repo.
Just to make sure we're on the same page... you are talking about
	[remote "myremote"]
not
	[alias]
		myremote = ...
yes? If so, please avoid using the term "alias"...
Further, I assume that your .gitconfig lists the "myremote" without a URL?
Also:
Show 5 quoted lines
> -       if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||
> -                       remote->fetch_refspec_nr))
> -               die(_("remote %s already exists."), name);
> +       if (remote && (remote->url_nr > 1 || remote->fetch_refspec_nr))
> +               die(_("remote %s %s already exists."), name, url);

The real problem here is that strcmp() is performed even if url_nr == 0, *and* that it compares the name – instead of the url – to the remote's URL. That is incorrect, so the correct fix would be:

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

In other words, we would still verify that there is no existing remote, even if that remote was declared in ~/.gitconfig. However, if a remote exists without any URL, or if it has a single URL that matches the provided one, and there are no fetch refspecs, *then* there is nothing to complain about and we continue.

Ciao, Johannes

Previous: Anastas DanchaNext: Anastas Dancha
Message 2 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.