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