{"thread":{"id":"38182","subject":"[PATCH] remote: allow adding remote w same name as alias","startedAt":"2014-12-16T02:30:30Z","lastAt":"2014-12-23T18:51:15Z","messageCount":19,"participants":["Anastas Dancha","Johannes Schindelin","Michael J Gruber","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"253719","messageId":"20141216021900.50095.24877@random.io","threadId":"38182","inReplyTo":null,"subject":"[PATCH] remote: allow adding remote w same name as alias","fromName":"Anastas Dancha","fromEmail":"anapsix@random.io","sentAt":"2014-12-16T02:30:30Z","receivedAt":"2014-12-16T02:30:30Z","isPatch":true,"sender":{"key":"anapsix@random.io","avatar":"https://gravatar.com/avatar/12939b22471e75b76b0be717f81fa0fbcba3b3aec39a1137d4ffc3f5fb88e4ea?d=mp&s=160"},"body":">From f80bdf3272e7bdf790ee67fb94196a8aa139331f Mon Sep 17 00:00:00 2001\nFrom: Anastas Dancha <anapsix@random.io>\nDate: Mon, 15 Dec 2014 16:30:50 -0500\nSubject: [PATCH] remote: allow adding remote w same name as alias\n\nWhen ~/.gitconfig contains an alias (i.e. myremote)\nand you are adding a new remote using the same name\nfor remote, Git will refuse to add the remote with\nthe same name as one of the aliases, even though the\nremote with such name is not setup for current repo.\n\n$ git remote add myremote git@host.com:team/repo.git\nfatal: remote myremote already exists.\n\nThe fatal error comes from strcmp(name, remote->url[0])\ncondition, which compares a name of the new remote with\nexisting urls of all the remotes, including the ones\nfrom ~/.gitconfig (or global variant).\nI'm not sure why that is necessary, unless Git is meant\nto prevent users from naming their remotes as their\nremote aliases..\nImho, if someone want's to git remote add myremote\nmyremote, they should, since git-remote always takes\n2 arguments, first being the new remote's name and\nsecond being new remote's url (or alias, if set).\nThanks to @mymuss for sanity check and debugging.\n\nSigned-off-by: Anastas Dancha <anapsix@random.io>\n---\n builtin/remote.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 7f28f92..7471d0a 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -180,9 +180,8 @@ static int add(int argc, const char **argv)\n \turl = argv[1];\n \n \tremote = remote_get(name);\n-\tif (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n-\t\t\tremote->fetch_refspec_nr))\n-\t\tdie(_(\"remote %s already exists.\"), name);\n+\tif (remote && (remote->url_nr > 1 || remote->fetch_refspec_nr))\n+\t\tdie(_(\"remote %s %s already exists.\"), name, url);\n \n \tstrbuf_addf(&buf2, \"refs/heads/test:refs/remotes/%s/test\", name);\n \tif (!valid_fetch_refspec(buf2.buf))\n-- \n2.2.0\n"},{"id":"253722","messageId":"alpine.DEB.1.00.1412160944180.13845@s15462909.onlinehome-server.info","threadId":"38182","inReplyTo":"20141216021900.50095.24877@random.io","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-16T09:01:53Z","receivedAt":"2014-12-16T09:01:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Anastas,\n\nOn Tue, 16 Dec 2014, Anastas Dancha wrote:\n\n> When ~/.gitconfig contains an alias (i.e. myremote)\n> and you are adding a new remote using the same name\n> for remote, Git will refuse to add the remote with\n> the same name as one of the aliases, even though the\n> remote with such name is not setup for current repo.\n\nJust to make sure we're on the same page... you are talking about\n\n\t[remote \"myremote\"]\n\nnot\n\n\t[alias]\n\t\tmyremote = ...\n\nyes? If so, please avoid using the term \"alias\"...\n\nFurther, I assume that your .gitconfig lists the \"myremote\" without a URL?\n\nAlso:\n\n> -       if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n> -                       remote->fetch_refspec_nr))\n> -               die(_(\"remote %s already exists.\"), name);\n> +       if (remote && (remote->url_nr > 1 || remote->fetch_refspec_nr))\n> +               die(_(\"remote %s %s already exists.\"), name, url);\n\nThe real problem here is that strcmp() is performed even if url_nr == 0,\n*and* that it compares the name – instead of the url – to the remote's URL.\nThat is incorrect, so the correct fix would be:\n\n-       if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n+       if (remote && (remote->url_nr > 1 ||\n+\t\t\t(remote->url_nr == 1 && strcmp(url, remote->url[0])) ||\n                        remote->fetch_refspec_nr))\n                die(_(\"remote %s already exists.\"), name);\n\nIn other words, we would still verify that there is no existing remote,\neven if that remote was declared in ~/.gitconfig. However, if a remote\nexists without any URL, or if it has a single URL that matches the\nprovided one, and there are no fetch refspecs, *then* there is nothing to\ncomplain about and we continue.\n\nCiao,\nJohannes"},{"id":"253723","messageId":"548FFC74.7080307@drmicha.warpmail.net","threadId":"38182","inReplyTo":"20141216021900.50095.24877@random.io","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-16T09:33:40Z","receivedAt":"2014-12-16T09:33:40Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Anastas Dancha schrieb am 16.12.2014 um 03:30:\n> From f80bdf3272e7bdf790ee67fb94196a8aa139331f Mon Sep 17 00:00:00 2001\n> From: Anastas Dancha <anapsix@random.io>\n> Date: Mon, 15 Dec 2014 16:30:50 -0500\n> Subject: [PATCH] remote: allow adding remote w same name as alias\n> \n> When ~/.gitconfig contains an alias (i.e. myremote)\n> and you are adding a new remote using the same name\n> for remote, Git will refuse to add the remote with\n> the same name as one of the aliases, even though the\n> remote with such name is not setup for current repo.\n> \n> $ git remote add myremote git@host.com:team/repo.git\n> fatal: remote myremote already exists.\n> \n> The fatal error comes from strcmp(name, remote->url[0])\n> condition, which compares a name of the new remote with\n> existing urls of all the remotes, including the ones\n> from ~/.gitconfig (or global variant).\n> I'm not sure why that is necessary, unless Git is meant\n> to prevent users from naming their remotes as their\n> remote aliases..\n> Imho, if someone want's to git remote add myremote\n> myremote, they should, since git-remote always takes\n> 2 arguments, first being the new remote's name and\n> second being new remote's url (or alias, if set).\n\nWhile that is true for \"git remote\", it is wrong for \"git push\" and the\nlike, which takes \"remote name or remote URL\" as a parameter. Therefore,\nremote names and remote aliases need to be unique within the same namespace.\n\n> Thanks to @mymuss for sanity check and debugging.\n> \n> Signed-off-by: Anastas Dancha <anapsix@random.io>\n> ---\n>  builtin/remote.c | 5 ++---\n>  1 file changed, 2 insertions(+), 3 deletions(-)\n"},{"id":"253724","messageId":"CAChhagAFTxmFVvCUiKp3a369awPJtZEuVsfFMcdiqeB9ZwYnKg@mail.gmail.com","threadId":"38182","inReplyTo":"alpine.DEB.1.00.1412160944180.13845@s15462909.onlinehome-server.info","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Anastas Dancha","fromEmail":"anapsix@random.io","sentAt":"2014-12-16T14:57:29Z","receivedAt":"2014-12-16T14:57:29Z","isPatch":true,"sender":{"key":"anapsix@random.io","avatar":"https://gravatar.com/avatar/12939b22471e75b76b0be717f81fa0fbcba3b3aec39a1137d4ffc3f5fb88e4ea?d=mp&s=160"},"body":"My bad Johannes,\n\nThen I wrote \"alias\", I've meant the following:\n```\n[url \"git@githost.com\"]\ninsteadOf = myalias\npushInsteadOf = myalias\n```\nUnfortunately, your suggested fix will not allow my [poorly] described use case.\nHope this makes more sense now.\n\nThank you for looking into this.\n\n-Anastas\n\nOn Tue, Dec 16, 2014 at 4:01 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi Anastas,\n>\n> On Tue, 16 Dec 2014, Anastas Dancha wrote:\n>\n>> When ~/.gitconfig contains an alias (i.e. myremote)\n>> and you are adding a new remote using the same name\n>> for remote, Git will refuse to add the remote with\n>> the same name as one of the aliases, even though the\n>> remote with such name is not setup for current repo.\n>\n> Just to make sure we're on the same page... you are talking about\n>\n>         [remote \"myremote\"]\n>\n> not\n>\n>         [alias]\n>                 myremote = ...\n>\n> yes? If so, please avoid using the term \"alias\"...\n>\n> Further, I assume that your .gitconfig lists the \"myremote\" without a URL?\n>\n> Also:\n>\n>> -       if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n>> -                       remote->fetch_refspec_nr))\n>> -               die(_(\"remote %s already exists.\"), name);\n>> +       if (remote && (remote->url_nr > 1 || remote->fetch_refspec_nr))\n>> +               die(_(\"remote %s %s already exists.\"), name, url);\n>\n> The real problem here is that strcmp() is performed even if url_nr == 0,\n> *and* that it compares the name – instead of the url – to the remote's URL.\n> That is incorrect, so the correct fix would be:\n>\n> -       if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n> +       if (remote && (remote->url_nr > 1 ||\n> +                       (remote->url_nr == 1 && strcmp(url, remote->url[0])) ||\n>                         remote->fetch_refspec_nr))\n>                 die(_(\"remote %s already exists.\"), name);\n>\n> In other words, we would still verify that there is no existing remote,\n> even if that remote was declared in ~/.gitconfig. However, if a remote\n> exists without any URL, or if it has a single URL that matches the\n> provided one, and there are no fetch refspecs, *then* there is nothing to\n> complain about and we continue.\n>\n> Ciao,\n> Johannes\n"},{"id":"253829","messageId":"alpine.DEB.1.00.1412191034560.13845@s15462909.onlinehome-server.info","threadId":"38182","inReplyTo":"CAChhagAFTxmFVvCUiKp3a369awPJtZEuVsfFMcdiqeB9ZwYnKg@mail.gmail.com","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-19T09:37:51Z","receivedAt":"2014-12-19T09:37:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Anastas,\n\nOn Tue, 16 Dec 2014, Anastas Dancha wrote:\n\n> Then I wrote \"alias\", I've meant the following:\n> ```\n> [url \"git@githost.com\"]\n> insteadOf = myalias\n> pushInsteadOf = myalias\n> ```\n> Unfortunately, your suggested fix will not allow my [poorly] described\n> use case.\n\nThere is one bit left to clarify: let me guess, you have a $HOME/.gitconfig\nlike this:\n\n\t[url \"anastas@company.com\"]\n\t\tinsteadOf = backup\n\t\tpushInsteadOf = backup\n\nand then you want to add the \"backup\" remote in a Git working directory\nlike this:\n\n\tgit remote add backup me@my-laptop.local\n\nbut my suggested fix will still disallow this because the URL does not\nmatch the url.anastas@company.com.insteadOf?\n\nCiao,\nJohannes\n"},{"id":"253842","messageId":"CAChhagA7eZ_7=g-xhAusZ1NX085KLjPDRbgJwx00F4pgOURXnQ@mail.gmail.com","threadId":"38182","inReplyTo":"alpine.DEB.1.00.1412191034560.13845@s15462909.onlinehome-server.info","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Anastas Dancha","fromEmail":"anapsix@random.io","sentAt":"2014-12-19T15:44:56Z","receivedAt":"2014-12-19T15:44:56Z","isPatch":true,"sender":{"key":"anapsix@random.io","avatar":"https://gravatar.com/avatar/12939b22471e75b76b0be717f81fa0fbcba3b3aec39a1137d4ffc3f5fb88e4ea?d=mp&s=160"},"body":"Hello Johannes,\n\nOn Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> [...]\n> There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig\n> like this:\n>\n>         [url \"anastas@company.com\"]\n>                 insteadOf = backup\n>                 pushInsteadOf = backup\n>\n> and then you want to add the \"backup\" remote in a Git working directory\n> like this:\n>\n>         git remote add backup me@my-laptop.local\n>\n> but my suggested fix will still disallow this because the URL does not\n> match the url.anastas@company.com.insteadOf?\n>\n> Ciao,\n> Johannes\n\nPrecisely that. In fact, it will not work even if you do any of these:\n\n    git remote add backup anastas@company.com\n    git remote add backup anything@anyhost.com\n    git remote add backup backup\n\nThe original / current code and your suggested fix - both exhibit\nsimilar behaviour with the use cases I've described above.\n\nThanks,\nAnastas\n"},{"id":"253858","messageId":"54945297.3010409@drmicha.warpmail.net","threadId":"38182","inReplyTo":"CAChhagA7eZ_7=g-xhAusZ1NX085KLjPDRbgJwx00F4pgOURXnQ@mail.gmail.com","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-19T16:30:15Z","receivedAt":"2014-12-19T16:30:15Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Anastas Dancha schrieb am 19.12.2014 um 16:44:\n> Hello Johannes,\n> \n> On Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n>> [...]\n>> There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig\n>> like this:\n>>\n>>         [url \"anastas@company.com\"]\n>>                 insteadOf = backup\n>>                 pushInsteadOf = backup\n>>\n>> and then you want to add the \"backup\" remote in a Git working directory\n>> like this:\n>>\n>>         git remote add backup me@my-laptop.local\n>>\n>> but my suggested fix will still disallow this because the URL does not\n>> match the url.anastas@company.com.insteadOf?\n>>\n>> Ciao,\n>> Johannes\n> \n> Precisely that. In fact, it will not work even if you do any of these:\n> \n>     git remote add backup anastas@company.com\n>     git remote add backup anything@anyhost.com\n>     git remote add backup backup\n> \n> The original / current code and your suggested fix - both exhibit\n> similar behaviour with the use cases I've described above.\n> \n> Thanks,\n> Anastas\n> \n\nOK, I'll repeat it again: We cannot allow that.\n\n\"git push\" can take a url or a remote as a parameter. Which one is it if\nyou have a remote and a url (alias) with the same name?\n\nMichael\n"},{"id":"253881","messageId":"CAChhagCrGB1Jq=qZdQnW1EMzw=OPSHzQvXO=jVSnZ2DCEmvAaA@mail.gmail.com","threadId":"38182","inReplyTo":"54945297.3010409@drmicha.warpmail.net","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Anastas Dancha","fromEmail":"anapsix@random.io","sentAt":"2014-12-20T20:57:45Z","receivedAt":"2014-12-20T20:57:45Z","isPatch":true,"sender":{"key":"anapsix@random.io","avatar":"https://gravatar.com/avatar/12939b22471e75b76b0be717f81fa0fbcba3b3aec39a1137d4ffc3f5fb88e4ea?d=mp&s=160"},"body":"On Fri, Dec 19, 2014 at 11:30 AM, Michael J Gruber\n<git@drmicha.warpmail.net> wrote:\n> Anastas Dancha schrieb am 19.12.2014 um 16:44:\n>> Hello Johannes,\n>>\n>> On Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin\n>> <Johannes.Schindelin@gmx.de> wrote:\n>>> [...]\n>>> There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig\n>>> like this:\n>>>\n>>>         [url \"anastas@company.com\"]\n>>>                 insteadOf = backup\n>>>                 pushInsteadOf = backup\n>>>\n>>> and then you want to add the \"backup\" remote in a Git working directory\n>>> like this:\n>>>\n>>>         git remote add backup me@my-laptop.local\n>>>\n>>> but my suggested fix will still disallow this because the URL does not\n>>> match the url.anastas@company.com.insteadOf?\n>>>\n>>> Ciao,\n>>> Johannes\n>>\n>> Precisely that. In fact, it will not work even if you do any of these:\n>>\n>>     git remote add backup anastas@company.com\n>>     git remote add backup anything@anyhost.com\n>>     git remote add backup backup\n>>\n>> The original / current code and your suggested fix - both exhibit\n>> similar behaviour with the use cases I've described above.\n>>\n>> Thanks,\n>> Anastas\n>>\n>\n> OK, I'll repeat it again: We cannot allow that.\n>\n> \"git push\" can take a url or a remote as a parameter. Which one is it if\n> you have a remote and a url (alias) with the same name?\n>\n> Michael\n\nI suppose it could be either. A string can be checked if there is a\nremote with such name first, and if not, it could be attempted to be\nused as a url.\nIn fact, my current workaround involves the following:\n\n    git remote add tempname backup:product/repo.git\n    git remote rename tempname backup\n    git push backup\n\nThis seems to work just fine right now with no code changes.\nMichael, could you explain in more detail what will break in **git\npush backup** if code changes are made to eliminate the necessity of\nthe add/remote workaround.\n\nRegards,\nAnastas\n"},{"id":"253905","messageId":"alpine.DEB.1.00.1412212139430.21312@s15462909.onlinehome-server.info","threadId":"38182","inReplyTo":"CAChhagA7eZ_7=g-xhAusZ1NX085KLjPDRbgJwx00F4pgOURXnQ@mail.gmail.com","subject":"Re: [PATCH] remote: allow adding remote w same name as alias","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-21T20:40:30Z","receivedAt":"2014-12-21T20:40:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Anastas,\n\nOn Fri, 19 Dec 2014, Anastas Dancha wrote:\n\n> On Fri, Dec 19, 2014 at 4:37 AM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > [...]\n> > There is one bit left to clarify: let me guess, you have a $HOME/.gitconfig\n> > like this:\n> >\n> >         [url \"anastas@company.com\"]\n> >                 insteadOf = backup\n> >                 pushInsteadOf = backup\n> >\n> > and then you want to add the \"backup\" remote in a Git working directory\n> > like this:\n> >\n> >         git remote add backup me@my-laptop.local\n> >\n> > but my suggested fix will still disallow this because the URL does not\n> > match the url.anastas@company.com.insteadOf?\n> \n> Precisely that. In fact, it will not work even if you do any of these:\n> \n>     git remote add backup anastas@company.com\n\nThis will succeed after applying my suggested change. I even tested this\n;-)\n\nCiao,\nJohannes\n"},{"id":"253926","messageId":"cover.1419267895.git.johannes.schindelin@gmx.de","threadId":"38182","inReplyTo":"20141216021900.50095.24877@random.io","subject":"[PATCH 0/2] Let `git remote add` play nicer with url.<url>.insteadOf","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-22T17:06:46Z","receivedAt":"2014-12-22T17:06:46Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Anastas Dancha reported that it is not possible to add a remote when\nthere is already a url.<url>.insteadOf = <nick> setting in\n$HOME/.gitconfig.\n\nWhile it makes sense to prevent surprises when a user adds a remote and\nit fetches from somewhere completely different, it makes less sense to\nprevent adding a remote when it is actually the same that was specified\nin the config.\n\nTherefore we add just another check that let's `git remote add` continue\nwhen the \"existing\" remote's URL is identical to the specified one.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\n\nJohannes Schindelin (2):\n  git remote add: allow re-adding remotes with the same URL\n  Add a regression test for 'git remote add <existing> <same-url>'\n\n builtin/remote.c  | 3 ++-\n t/t5505-remote.sh | 5 +++++\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\n-- \n2.0.0.rc3.9669.g840d1f9\n"},{"id":"253925","messageId":"9c0c693efe68b1c0b080c14104bb6c5f7bf74097.1419267895.git.johannes.schindelin@gmx.de","threadId":"38182","inReplyTo":"cover.1419267895.git.johannes.schindelin@gmx.de","subject":"[PATCH 1/2] git remote add: allow re-adding remotes with the same URL","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-22T17:06:50Z","receivedAt":"2014-12-22T17:06:50Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When adding a remote, we make sure that the remote does not exist\nalready.\n\nFor convenience, we allow re-adding remotes with the same URLs.\nThis also handles the case that there is an \"[url ...] insteadOf\"\nsetting in the config.\n\nIt might seem like a mistake to compare against remote->url[0] without\nverifying that remote->url_nr >=1, but at this point a missing URL has\nbeen filled by the name already, therefore url_nr cannot be zero.\n\nNoticed by Anastas Dancha.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/remote.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 46ecfd9..9168c83 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -180,7 +180,8 @@ static int add(int argc, const char **argv)\n \turl = argv[1];\n \n \tremote = remote_get(name);\n-\tif (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n+\tif (remote && (remote->url_nr > 1 || (strcmp(name, remote->url[0]) &&\n+\t\t\t\tstrcmp(url, remote->url[0])) ||\n \t\t\tremote->fetch_refspec_nr))\n \t\tdie(_(\"remote %s already exists.\"), name);\n \n-- \n2.0.0.rc3.9669.g840d1f9\n"},{"id":"253927","messageId":"05b1bc322b77418442d504402132a244216a4e3c.1419267895.git.johannes.schindelin@gmx.de","threadId":"38182","inReplyTo":"cover.1419267895.git.johannes.schindelin@gmx.de","subject":"[PATCH 2/2] Add a regression test for 'git remote add <existing> <same-url>'","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-22T17:06:54Z","receivedAt":"2014-12-22T17:06:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n t/t5505-remote.sh | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nindex ac79dd9..17c6330 100755\n--- a/t/t5505-remote.sh\n+++ b/t/t5505-remote.sh\n@@ -1113,4 +1113,9 @@ test_extra_arg set-url origin newurl oldurl\n # prune takes any number of args\n # update takes any number of args\n \n+test_expect_success 'add remote matching the \"insteadOf\" URL' '\n+\tgit config url.xyz@example.com.insteadOf backup &&\n+\tgit remote add backup xyz@example.com\n+'\n+\n test_done\n-- \n2.0.0.rc3.9669.g840d1f9\n"},{"id":"253931","messageId":"xmqq1tnrbmn1.fsf@gitster.dls.corp.google.com","threadId":"38182","inReplyTo":"9c0c693efe68b1c0b080c14104bb6c5f7bf74097.1419267895.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH 1/2] git remote add: allow re-adding remotes with the same URL","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-22T17:49:22Z","receivedAt":"2014-12-22T17:49:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <johannes.schindelin@gmx.de> writes:\n\n> When adding a remote, we make sure that the remote does not exist\n> already.\n>\n> For convenience, we allow re-adding remotes with the same URLs.\n> This also handles the case that there is an \"[url ...] insteadOf\"\n> setting in the config.\n>\n> It might seem like a mistake to compare against remote->url[0] without\n> verifying that remote->url_nr >=1, but at this point a missing URL has\n> been filled by the name already, therefore url_nr cannot be zero.\n>\n> Noticed by Anastas Dancha.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>  builtin/remote.c | 3 ++-\n>  1 file changed, 2 insertions(+), 1 deletion(-)\n>\n> diff --git a/builtin/remote.c b/builtin/remote.c\n> index 46ecfd9..9168c83 100644\n> --- a/builtin/remote.c\n> +++ b/builtin/remote.c\n> @@ -180,7 +180,8 @@ static int add(int argc, const char **argv)\n>  \turl = argv[1];\n>  \n>  \tremote = remote_get(name);\n> -\tif (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n> +\tif (remote && (remote->url_nr > 1 || (strcmp(name, remote->url[0]) &&\n> +\t\t\t\tstrcmp(url, remote->url[0])) ||\n>  \t\t\tremote->fetch_refspec_nr))\n>  \t\tdie(_(\"remote %s already exists.\"), name);\n\nWhen we need to fold an overlong line, it is easier to read if the\nline is folded at an operator with higher precedence, i.e. this line\n\n        if (A && (B || (C && D) || E))\n\nfolded like this\n\n        if (A && (B || (C &&\n                   D) ||\n            E))\n\nis harder to read than when folded like this\n\n        if (A && (B ||\n                  (C && D) ||\n                   E))\n\nSo, it is an error if we have \"remote\" and if\n\n (1) URL for the remote is defined already twice or more; or\n (2) we are adding a nickname (i.e. not a URL) and it is different\n     from what we already have; or\n (3) we already have fetch_refspec\n\nThe way I read the log message's rationale was that this is to allow\nreplacing an existing remote's URL; wouldn't checking the existence\nof fetch_refspec go against that goal?\n\nPuzzled.  Either the code is wrong or I am mislead by the\nexplanation in the log.\n"},{"id":"254005","messageId":"cover.1419340898.git.johannes.schindelin@gmx.de","threadId":"38182","inReplyTo":"20141216021900.50095.24877@random.io","subject":"[PATCH v2 0/2] Let `git remote add` play nicer with url.<url>.insteadOf","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-23T13:24:50Z","receivedAt":"2014-12-23T13:24:50Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Anastas Dancha reported that it is not possible to add a remote when\nthere is already a url.<url>.insteadOf = <nick> setting in\n$HOME/.gitconfig.\n\nWhile it makes sense to prevent surprises when a user adds a remote and\nit fetches from somewhere completely different, it makes less sense to\nprevent adding a remote when it is actually the same that was specified\nin the config.\n\nTherefore we add just another check that let's `git remote add` continue\nwhen the \"existing\" remote's URL is identical to the specified one.\n\nInterdiff below the diffstat (the commit message was also touched up to\nstop pretending that we allow adding a remote twice when the URL did not\nchange).\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nJohannes Schindelin (2):\n  git remote: allow adding remotes agreeing with url.<...>.insteadOf\n  Add a regression test for 'git remote add <existing> <same-url>'\n\n builtin/remote.c  | 4 +++-\n t/t5505-remote.sh | 5 +++++\n 2 files changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 9168c83..b4ff468 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -180,7 +180,8 @@ static int add(int argc, const char **argv)\n \turl = argv[1];\n \n \tremote = remote_get(name);\n-\tif (remote && (remote->url_nr > 1 || (strcmp(name, remote->url[0]) &&\n+\tif (remote && (remote->url_nr > 1 ||\n+\t\t\t(strcmp(name, remote->url[0]) &&\n \t\t\t\tstrcmp(url, remote->url[0])) ||\n \t\t\tremote->fetch_refspec_nr))\n \t\tdie(_(\"remote %s already exists.\"), name);\n-- \n2.0.0.rc3.9669.g840d1f9\n"},{"id":"254006","messageId":"cf69aaaae4a93ddf2b592c99887669511aa0bf58.1419340898.git.johannes.schindelin@gmx.de","threadId":"38182","inReplyTo":"cover.1419340898.git.johannes.schindelin@gmx.de","subject":"[PATCH v2 1/2] git remote: allow adding remotes agreeing with url.<...>.insteadOf","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-23T13:25:05Z","receivedAt":"2014-12-23T13:25:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When adding a remote, we make sure that the remote does not exist\nalready. However, this test was not quite correct: when the\nurl.<...>.insteadOf config variable was set to the remote name to be\nadded, the code would assume that the remote exists already.\n\nLet's allow adding remotes when there is a url.<...>.insteadOf setting\nwhen both the name and the URL agree with the remote to be added.\n\nIt might seem like a mistake to compare against remote->url[0] without\nverifying that remote->url_nr >=1, but at this point a missing URL has\nbeen filled by the name already, therefore url_nr cannot be zero.\n\nNoticed by Anastas Dancha.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n builtin/remote.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 46ecfd9..b4ff468 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -180,7 +180,9 @@ static int add(int argc, const char **argv)\n \turl = argv[1];\n \n \tremote = remote_get(name);\n-\tif (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n+\tif (remote && (remote->url_nr > 1 ||\n+\t\t\t(strcmp(name, remote->url[0]) &&\n+\t\t\t\tstrcmp(url, remote->url[0])) ||\n \t\t\tremote->fetch_refspec_nr))\n \t\tdie(_(\"remote %s already exists.\"), name);\n \n-- \n2.0.0.rc3.9669.g840d1f9\n"},{"id":"254007","messageId":"c1fcf95b1329df7c9b88b41adaa3010e5c3c3729.1419340898.git.johannes.schindelin@gmx.de","threadId":"38182","inReplyTo":"cover.1419340898.git.johannes.schindelin@gmx.de","subject":"[PATCH v2 2/2] Add a regression test for 'git remote add <existing> <same-url>'","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-23T13:25:09Z","receivedAt":"2014-12-23T13:25:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n t/t5505-remote.sh | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nindex ac79dd9..17c6330 100755\n--- a/t/t5505-remote.sh\n+++ b/t/t5505-remote.sh\n@@ -1113,4 +1113,9 @@ test_extra_arg set-url origin newurl oldurl\n # prune takes any number of args\n # update takes any number of args\n \n+test_expect_success 'add remote matching the \"insteadOf\" URL' '\n+\tgit config url.xyz@example.com.insteadOf backup &&\n+\tgit remote add backup xyz@example.com\n+'\n+\n test_done\n-- \n2.0.0.rc3.9669.g840d1f9\n"},{"id":"254008","messageId":"alpine.DEB.1.00.1412231425220.21312@s15462909.onlinehome-server.info","threadId":"38182","inReplyTo":"xmqq1tnrbmn1.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 1/2] git remote add: allow re-adding remotes with the same URL","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-23T13:25:36Z","receivedAt":"2014-12-23T13:25:36Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Mon, 22 Dec 2014, Junio C Hamano wrote:\n\n> Johannes Schindelin <johannes.schindelin@gmx.de> writes:\n> \n> > When adding a remote, we make sure that the remote does not exist\n> > already.\n> >\n> > For convenience, we allow re-adding remotes with the same URLs.\n> > This also handles the case that there is an \"[url ...] insteadOf\"\n> > setting in the config.\n> >\n> > It might seem like a mistake to compare against remote->url[0] without\n> > verifying that remote->url_nr >=1, but at this point a missing URL has\n> > been filled by the name already, therefore url_nr cannot be zero.\n> >\n> > Noticed by Anastas Dancha.\n> >\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> >  builtin/remote.c | 3 ++-\n> >  1 file changed, 2 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/builtin/remote.c b/builtin/remote.c\n> > index 46ecfd9..9168c83 100644\n> > --- a/builtin/remote.c\n> > +++ b/builtin/remote.c\n> > @@ -180,7 +180,8 @@ static int add(int argc, const char **argv)\n> >  \turl = argv[1];\n> >  \n> >  \tremote = remote_get(name);\n> > -\tif (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||\n> > +\tif (remote && (remote->url_nr > 1 || (strcmp(name, remote->url[0]) &&\n> > +\t\t\t\tstrcmp(url, remote->url[0])) ||\n> >  \t\t\tremote->fetch_refspec_nr))\n> >  \t\tdie(_(\"remote %s already exists.\"), name);\n> \n> When we need to fold an overlong line, it is easier to read if the\n> line is folded at an operator with higher precedence, i.e. this line\n> \n>         if (A && (B || (C && D) || E))\n> \n> folded like this\n> \n>         if (A && (B || (C &&\n>                    D) ||\n>             E))\n> \n> is harder to read than when folded like this\n> \n>         if (A && (B ||\n>                   (C && D) ||\n>                    E))\n> \n> So, it is an error if we have \"remote\" and if\n> \n>  (1) URL for the remote is defined already twice or more; or\n>  (2) we are adding a nickname (i.e. not a URL) and it is different\n>      from what we already have; or\n>  (3) we already have fetch_refspec\n> \n> The way I read the log message's rationale was that this is to allow\n> replacing an existing remote's URL; wouldn't checking the existence\n> of fetch_refspec go against that goal?\n> \n> Puzzled.  Either the code is wrong or I am mislead by the\n> explanation in the log.\n\nI hope v2 addresses your concerns.\n\nCiao,\nDscho\n"},{"id":"254035","messageId":"alpine.DEB.1.00.1412231923560.21312@s15462909.onlinehome-server.info","threadId":"38182","inReplyTo":"CAPc5daXcXs+Sw8jr65dmLnpf6LQ6Lr34y80bxSf2AhhFyXa_mQ@mail.gmail.com","subject":"Re: [PATCH 1/2] git remote add: allow re-adding remotes with the same URL","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-23T18:26:55Z","receivedAt":"2014-12-23T18:26:55Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\n[re-Cc:ing the list]\n\nOn Tue, 23 Dec 2014, Junio C Hamano wrote:\n\n> On Tue, Dec 23, 2014 at 5:25 AM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > On Mon, 22 Dec 2014, Junio C Hamano wrote:\n> >>\n> >> So, it is an error if we have \"remote\" and if\n> >>\n> >>  (1) URL for the remote is defined already twice or more; or\n> >>  (2) we are adding a nickname (i.e. not a URL) and it is different\n> >>      from what we already have; or\n> >>  (3) we already have fetch_refspec\n> >>\n> >> The way I read the log message's rationale was that this is to allow\n> >> replacing an existing remote's URL; wouldn't checking the existence\n> >> of fetch_refspec go against that goal?\n> >>\n> >> Puzzled.  Either the code is wrong or I am mislead by the\n> >> explanation in the log.\n> >\n> > I hope v2 addresses your concerns.\n> \n> Unfortunately I am still confused.\n> \n> The way the overlong line is folded in the new version of the patch\n> makes it easier to read, but I didn't find a reason why checking the\n> number of fetch_refspec does not go against that goal there.\n\nSince you pointed out rightfully that the main goal is *not* to allow\nmultiple `git remote add` to succeed when they try to add the same remote\nwith the same URL, I changed the commit message to point out that the goal\nwas to handle adding remotes via `git remote add <nick> <url>` when\nurl.<url>.insteadOf = <nick> already exists, with the same <nick> and\n<url>.\n\nSince I have no interest in opening the can of worms to allow re-adding\nremotes, I did not touch that part at all, I hope you do not mind.\n\nCiao,\nDscho\n"},{"id":"254037","messageId":"xmqq8uhy2o9o.fsf@gitster.dls.corp.google.com","threadId":"38182","inReplyTo":"alpine.DEB.1.00.1412231923560.21312@s15462909.onlinehome-server.info","subject":"Re: [PATCH 1/2] git remote add: allow re-adding remotes with the same URL","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-23T18:51:15Z","receivedAt":"2014-12-23T18:51:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n>> > I hope v2 addresses your concerns.\n>> \n>> Unfortunately I am still confused.\n>> \n>> The way the overlong line is folded in the new version of the patch\n>> makes it easier to read, but I didn't find a reason why checking the\n>> number of fetch_refspec does not go against that goal there.\n>\n> Since you pointed out rightfully that the main goal is *not* to allow\n> multiple `git remote add` to succeed when they try to add the same remote\n> with the same URL, I changed the commit message to point out that the goal\n> was to handle adding remotes via `git remote add <nick> <url>` when\n> url.<url>.insteadOf = <nick> already exists, with the same <nick> and\n> <url>.\n>\n> Since I have no interest in opening the can of worms to allow re-adding\n> remotes, I did not touch that part at all, I hope you do not mind.\n\nOh, don't get me wrong.  I do not have any interest in allowing\nre-adding remotes, either, so we are on the same page.\n\nI was just saying that it was unclear what ensures that the change\nin the codepath only affects the remote setting that conflicts with\n\"insteadOf\" without randomly (read: sometimes it allows, sometimes\nit forbids) allowing re-adding remotes.\n"}]}