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

2014-12-16 Thread Johannes Schindelin
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

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

2014-12-16 Thread Michael J Gruber
Anastas Dancha schrieb am 16.12.2014 um 03:30:
> From f80bdf3272e7bdf790ee67fb94196a8aa139331f Mon Sep 17 00:00:00 2001
> From: Anastas Dancha 
> Date: Mon, 15 Dec 2014 16:30:50 -0500
> Subject: [PATCH] remote: allow adding remote w same name as alias
> 
> 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.
> 
> $ git remote add myremote g...@host.com:team/repo.git
> fatal: remote myremote already exists.
> 
> The fatal error comes from strcmp(name, remote->url[0])
> condition, which compares a name of the new remote with
> existing urls of all the remotes, including the ones
> from ~/.gitconfig (or global variant).
> I'm not sure why that is necessary, unless Git is meant
> to prevent users from naming their remotes as their
> remote aliases..
> Imho, if someone want's to git remote add myremote
> myremote, they should, since git-remote always takes
> 2 arguments, first being the new remote's name and
> second being new remote's url (or alias, if set).

While that is true for "git remote", it is wrong for "git push" and the
like, which takes "remote name or remote URL" as a parameter. Therefore,
remote names and remote aliases need to be unique within the same namespace.

> Thanks to @mymuss for sanity check and debugging.
> 
> Signed-off-by: Anastas Dancha 
> ---
>  builtin/remote.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2014-12-16 Thread Anastas Dancha
My bad Johannes,

Then I wrote "alias", I've meant the following:
```
[url "g...@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
 wrote:
> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2014-12-19 Thread Johannes Schindelin
Hi Anastas,

On Tue, 16 Dec 2014, Anastas Dancha wrote:

> Then I wrote "alias", I've meant the following:
> ```
> [url "g...@githost.com"]
> insteadOf = myalias
> pushInsteadOf = myalias
> ```
> Unfortunately, your suggested fix will not allow my [poorly] described
> use case.

There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig
like this:

[url "anas...@company.com"]
insteadOf = backup
pushInsteadOf = backup

and then you want to add the "backup" remote in a Git working directory
like this:

git remote add backup me@my-laptop.local

but my suggested fix will still disallow this because the URL does not
match the url.anas...@company.com.insteadOf?

Ciao,
Johannes
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2014-12-19 Thread Anastas Dancha
Hello Johannes,

On Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin
 wrote:
> [...]
> There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig
> like this:
>
> [url "anas...@company.com"]
> insteadOf = backup
> pushInsteadOf = backup
>
> and then you want to add the "backup" remote in a Git working directory
> like this:
>
> git remote add backup me@my-laptop.local
>
> but my suggested fix will still disallow this because the URL does not
> match the url.anas...@company.com.insteadOf?
>
> Ciao,
> Johannes

Precisely that. In fact, it will not work even if you do any of these:

git remote add backup anas...@company.com
git remote add backup anyth...@anyhost.com
git remote add backup backup

The original / current code and your suggested fix - both exhibit
similar behaviour with the use cases I've described above.

Thanks,
Anastas
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2014-12-19 Thread Michael J Gruber
Anastas Dancha schrieb am 19.12.2014 um 16:44:
> Hello Johannes,
> 
> On Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin
>  wrote:
>> [...]
>> There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig
>> like this:
>>
>> [url "anas...@company.com"]
>> insteadOf = backup
>> pushInsteadOf = backup
>>
>> and then you want to add the "backup" remote in a Git working directory
>> like this:
>>
>> git remote add backup me@my-laptop.local
>>
>> but my suggested fix will still disallow this because the URL does not
>> match the url.anas...@company.com.insteadOf?
>>
>> Ciao,
>> Johannes
> 
> Precisely that. In fact, it will not work even if you do any of these:
> 
> git remote add backup anas...@company.com
> git remote add backup anyth...@anyhost.com
> git remote add backup backup
> 
> The original / current code and your suggested fix - both exhibit
> similar behaviour with the use cases I've described above.
> 
> Thanks,
> Anastas
> 

OK, I'll repeat it again: We cannot allow that.

"git push" can take a url or a remote as a parameter. Which one is it if
you have a remote and a url (alias) with the same name?

Michael
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2014-12-20 Thread Anastas Dancha
On Fri, Dec 19, 2014 at 11:30 AM, Michael J Gruber
 wrote:
> Anastas Dancha schrieb am 19.12.2014 um 16:44:
>> Hello Johannes,
>>
>> On Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin
>>  wrote:
>>> [...]
>>> There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig
>>> like this:
>>>
>>> [url "anas...@company.com"]
>>> insteadOf = backup
>>> pushInsteadOf = backup
>>>
>>> and then you want to add the "backup" remote in a Git working directory
>>> like this:
>>>
>>> git remote add backup me@my-laptop.local
>>>
>>> but my suggested fix will still disallow this because the URL does not
>>> match the url.anas...@company.com.insteadOf?
>>>
>>> Ciao,
>>> Johannes
>>
>> Precisely that. In fact, it will not work even if you do any of these:
>>
>> git remote add backup anas...@company.com
>> git remote add backup anyth...@anyhost.com
>> git remote add backup backup
>>
>> The original / current code and your suggested fix - both exhibit
>> similar behaviour with the use cases I've described above.
>>
>> Thanks,
>> Anastas
>>
>
> OK, I'll repeat it again: We cannot allow that.
>
> "git push" can take a url or a remote as a parameter. Which one is it if
> you have a remote and a url (alias) with the same name?
>
> Michael

I suppose it could be either. A string can be checked if there is a
remote with such name first, and if not, it could be attempted to be
used as a url.
In fact, my current workaround involves the following:

git remote add tempname backup:product/repo.git
git remote rename tempname backup
git push backup

This seems to work just fine right now with no code changes.
Michael, could you explain in more detail what will break in **git
push backup** if code changes are made to eliminate the necessity of
the add/remote workaround.

Regards,
Anastas
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2014-12-21 Thread Johannes Schindelin
Hi Anastas,

On Fri, 19 Dec 2014, Anastas Dancha wrote:

> On Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin
>  wrote:
> > [...]
> > There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig
> > like this:
> >
> > [url "anas...@company.com"]
> > insteadOf = backup
> > pushInsteadOf = backup
> >
> > and then you want to add the "backup" remote in a Git working directory
> > like this:
> >
> > git remote add backup me@my-laptop.local
> >
> > but my suggested fix will still disallow this because the URL does not
> > match the url.anas...@company.com.insteadOf?
> 
> Precisely that. In fact, it will not work even if you do any of these:
> 
> git remote add backup anas...@company.com

This will succeed after applying my suggested change. I even tested this
;-)

Ciao,
Johannes
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html