Re: [PATCH] remote: allow adding remote w same name as alias
- From
Anastas Dancha <anapsix@random.io>
- Date
- Dec 16, 2014, 14:57 UTC
- Message-ID
- <CAChhagAFTxmFVvCUiKp3a369awPJtZEuVsfFMcdiqeB9ZwYnKg@mail.gmail.com>
- In-Reply-To
- <alpine.DEB.1.00.1412160944180.13845@s15462909.onlinehome-server.info>
My bad Johannes,
Then I wrote "alias", I've meant the following: ``` [url "git@githost.com"] insteadOf = myalias pushInsteadOf = myalias ``` Unfortunately, your suggested fix will not allow my [poorly] described use case. Hope this makes more sense now.
Thank you for looking into this.
-Anastas
On Tue, Dec 16, 2014 at 4:01 AM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 49 quoted lines
> Hi Anastas,
>
> On Tue, 16 Dec 2014, Anastas Dancha wrote:
>
>> 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:
>
>> - 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