{"thread":{"id":"15100","subject":"[PATCH] git-submodule.sh - Remove trailing / from URL if found","startedAt":"2008-08-20T02:18:23Z","lastAt":"2008-08-21T23:54:01Z","messageCount":7,"participants":["Mark Levedahl","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"87781","messageId":"1219198703-2388-1-git-send-email-mlevedahl@gmail.com","threadId":"15100","inReplyTo":null,"subject":"[PATCH] git-submodule.sh - Remove trailing / from URL if found","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2008-08-20T02:18:23Z","receivedAt":"2008-08-20T02:18:23Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"git clone does not complain if a trailing '/' is included in the origin\nURL, but doing so causes resolution of a submodule's URL relative to the\nsuperproject to fail. Regardless of whether git is changed to remove the\ntrailing / before recording the URL, we should avoid this issue in\nsubmodule as existing repositories can have this problem.\n\nSigned-off-by: Mark Levedahl <mlevedahl@gmail.com>\n---\n git-submodule.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ea6357b..fa9dd3a 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -34,7 +34,7 @@ resolve_relative_url ()\n \tremote=$(get_default_remote)\n \tremoteurl=$(git config \"remote.$remote.url\") ||\n \t\tdie \"remote ($remote) does not have a url in .git/config\"\n-\turl=\"$1\"\n+\turl=\"${1%/}\"\n \twhile test -n \"$url\"\n \tdo\n \t\tcase \"$url\" in\n-- \n1.6.0.22.g2957\n"},{"id":"87793","messageId":"7vpro4tjkw.fsf@gitster.siamese.dyndns.org","threadId":"15100","inReplyTo":"1219198703-2388-1-git-send-email-mlevedahl@gmail.com","subject":"Re: [PATCH] git-submodule.sh - Remove trailing / from URL if found","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-20T04:07:59Z","receivedAt":"2008-08-20T04:07:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mark Levedahl <mlevedahl@gmail.com> writes:\n\n> git clone does not complain if a trailing '/' is included in the origin\n> URL, but doing so causes resolution of a submodule's URL relative to the\n> superproject to fail. Regardless of whether git is changed to remove the\n> trailing / before recording the URL, we should avoid this issue in\n> submodule as existing repositories can have this problem.\n>\n> Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>\n> ---\n>  git-submodule.sh |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n>\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index ea6357b..fa9dd3a 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -34,7 +34,7 @@ resolve_relative_url ()\n>  \tremote=$(get_default_remote)\n>  \tremoteurl=$(git config \"remote.$remote.url\") ||\n>  \t\tdie \"remote ($remote) does not have a url in .git/config\"\n> -\turl=\"$1\"\n> +\turl=\"${1%/}\"\n>  \twhile test -n \"$url\"\n>  \tdo\n>  \t\tcase \"$url\" in\n\nHmm, the case arms outside the context looks like this:\n\n\twhile test -n \"$url\"\n\tdo\n\t\tcase \"$url\" in\n\t\t../*)\n\t\t\turl=\"${url#../}\"\n\t\t\tremoteurl=\"${remoteurl%/*}\"\n\t\t\t;;\n\t\t./*)\n\t\t\turl=\"${url#./}\"\n\t\t\t;;\n\t\t*)\n\t\t\tbreak;;\n\t\tesac\n\tdone\n\techo \"$remoteurl/$url\"\n\nIf you call \"resolve_relative_url ../\", the first arm used to fire once\nand stripped one level away, but with your patch it does not do so\nanymore, and returns \"$remoteurl/..\" instead?\n\nI know you are primarily interested in making sure that \"../foo\" and\n\"../foo/\" are handled the same way, but somehow this change does not feel\nright.  How about stripping the trailing slash from the end result?\n"},{"id":"87913","messageId":"1219280847-872-1-git-send-email-mlevedahl@gmail.com","threadId":"15100","inReplyTo":"7vpro4tjkw.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] git-submodule.sh - Remove trailing / from URL if found","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2008-08-21T01:07:27Z","receivedAt":"2008-08-21T01:07:27Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"git clone does not complain if a trailing '/' is included in the origin\nURL, but doing so causes resolution of a submodule's URL relative to the\nsuperproject to fail. Trailing /'s are likely when cloning locally using\ntab-completion, so the slash may appear in either superproject or\nsubmodule URL. So, ignore the trailing slash if it already exists in\nthe superproject's URL, and don't record one for the submodule (which\ncould itself have submodules...).\n\nSigned-off-by: Mark Levedahl <mlevedahl@gmail.com>\n---\n git-submodule.sh |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex b40f876..e576cd2 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -36,6 +36,7 @@ resolve_relative_url ()\n \tremoteurl=$(git config \"remote.$remote.url\") ||\n \t\tdie \"remote ($remote) does not have a url defined in .git/config\"\n \turl=\"$1\"\n+\tremoteurl=${remoteurl%/}\n \twhile test -n \"$url\"\n \tdo\n \t\tcase \"$url\" in\n@@ -50,7 +51,7 @@ resolve_relative_url ()\n \t\t\tbreak;;\n \t\tesac\n \tdone\n-\techo \"$remoteurl/$url\"\n+\techo \"$remoteurl\"/\"${url%/}\"\n }\n \n #\n-- \n1.6.0.22.g2957\n"},{"id":"87937","messageId":"7vfxozkpzi.fsf@gitster.siamese.dyndns.org","threadId":"15100","inReplyTo":"1219280847-872-1-git-send-email-mlevedahl@gmail.com","subject":"Re: [PATCH] git-submodule.sh - Remove trailing / from URL if found","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-21T03:26:41Z","receivedAt":"2008-08-21T03:26:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mark Levedahl <mlevedahl@gmail.com> writes:\n\n> git clone does not complain if a trailing '/' is included in the origin\n> URL, but doing so causes resolution of a submodule's URL relative to the\n> superproject to fail. Trailing /'s are likely when cloning locally using\n> tab-completion, so the slash may appear in either superproject or\n> submodule URL. So, ignore the trailing slash if it already exists in\n> the superproject's URL, and don't record one for the submodule (which\n> could itself have submodules...).\n>\n> Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>\n> ---\n>  git-submodule.sh |    3 ++-\n>  1 files changed, 2 insertions(+), 1 deletions(-)\n\nHmm.  I was sort of hoping to hear \"Junio you idiot you do not know what\nyou are talking about --- your example of using \"..\" as relative won't\nhappen because of such and such reasons; trust me I know what is going on\nin the vicinity of this code.\"\n\nAnd after looking at the callsites of the shell function, I think the\noriginal can never pass \"..\" (there are case statements to pass only $url\nthat match \"./*\" or \"../*\"), so I think both your original and this\nversion are safe as long as the part that match the trailing \"/*\" is\nsane.\n\nSo I'll queue your first patch, as it is slightly shorter ;-)\n\nThanks.\n"},{"id":"87971","messageId":"30e4a070808210504l1dd6b491l1d66dcd96a238ebc@mail.gmail.com","threadId":"15100","inReplyTo":"7vfxozkpzi.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-submodule.sh - Remove trailing / from URL if found","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2008-08-21T12:04:34Z","receivedAt":"2008-08-21T12:04:34Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"On Wed, Aug 20, 2008 at 11:26 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Hmm.  I was sort of hoping to hear \"Junio you idiot you do not know what\n> you are talking about --- your example of using \"..\" as relative won't\n> happen because of such and such reasons; trust me I know what is going on\n> in the vicinity of this code.\"\n>\n> And after looking at the callsites of the shell function, I think the\n> original can never pass \"..\" (there are case statements to pass only $url\n> that match \"./*\" or \"../*\"), so I think both your original and this\n> version are safe as long as the part that match the trailing \"/*\" is\n> sane.\n>\n> So I'll queue your first patch, as it is slightly shorter ;-)\n>\n> Thanks.\n>\n\nJunio,\n\nI try to avoid the \"idiot\" idiom, it tends to backfire ... :^)\n\nThe problem I'm trying to fix is that a number of folks have\nsuperprojects checked out where the recorded origin URL has a trailing\n/, and a submodule has its origin in a directory sitting right next to\nthe superproject on the server. Thus, we have:\n\n   superproject url = server:/public/super\n   submodoule url = server:/public/sub1\n\nHowever, in the checked out superproject's .git/config\n[remote \"origin\"]\n   url = server:/public/super/\n\nand for similar reasons, the submodule has its URL recorded in .gitmodules as\n[submodule \"sub\"]\n   path = submodule1\n   url = ../sub1/\n\nresolve_relative_url gets the submodule's recorded url as $1, which\nthe caller retrieved from .gitmodules, and retrieves the superprojects\norigin from .git/config. So in this case resolve_relative_url has\nthat:\n   url = ../sub1/\n   remoteurl = server:/public/super/\n\nSo, without any patch, resolve_relative_url computes the submodule's URL as:\n   server:/public/super/sub1/\n\nwith the first patch as:\n   server:/public/super/sub1\n\nand with the second as\n   server:/public/sub1\nrather than\n   server:/public/sub1\n\nSo, the second patch I sent is the one that fixes the above problem,\nand I have to say I now forget what the confused state of .gitmodules\n+ .git/config I found on one machine that lead to the first patch as\nbeing a correct fix.\n\nIn summary, it is essential that resolve_relative_url strip the\ntrailing / from the superproject's url before starting, while it is\nnice but not necessary if it assures that the result does not contain\na trailing /.\n\nMark\n"},{"id":"88016","messageId":"7vej4ii6y8.fsf@gitster.siamese.dyndns.org","threadId":"15100","inReplyTo":"30e4a070808210504l1dd6b491l1d66dcd96a238ebc@mail.gmail.com","subject":"Re: [PATCH] git-submodule.sh - Remove trailing / from URL if found","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-21T18:00:47Z","receivedAt":"2008-08-21T18:00:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Mark Levedahl\" <mlevedahl@gmail.com> writes:\n\n> The problem I'm trying to fix is that a number of folks have\n> superprojects checked out where the recorded origin URL has a trailing\n> /, and a submodule has its origin in a directory sitting right next to\n> the superproject on the server. Thus, we have:\n>\n>    superproject url = server:/public/super\n>    submodoule url = server:/public/sub1\n>\n> However, in the checked out superproject's .git/config\n> [remote \"origin\"]\n>    url = server:/public/super/\n>\n> and for similar reasons, the submodule has its URL recorded in .gitmodules as\n> [submodule \"sub\"]\n>    path = submodule1\n>    url = ../sub1/\n>\n> resolve_relative_url gets the submodule's recorded url as $1, which\n> the caller retrieved from .gitmodules, and retrieves the superprojects\n> origin from .git/config. So in this case resolve_relative_url has\n> that:\n>    url = ../sub1/\n>    remoteurl = server:/public/super/\n>\n> So, without any patch, resolve_relative_url computes the submodule's URL as:\n>    server:/public/super/sub1/\n>\n> with the first patch as:\n>    server:/public/super/sub1\n>\n> and with the second as\n>    server:/public/sub1\n> rather than\n>    server:/public/sub1\n>\n> So, the second patch I sent is the one that fixes the above problem,\n> and I have to say I now forget what the confused state of .gitmodules\n> + .git/config I found on one machine that lead to the first patch as\n> being a correct fix.\n>\n> In summary, it is essential that resolve_relative_url strip the\n> trailing / from the superproject's url before starting, while it is\n> nice but not necessary if it assures that the result does not contain\n> a trailing /.\n\nWell, that is a description worth having in the proposed commit log\nmessage, isn't it?\n"},{"id":"88064","messageId":"1219362841-4048-1-git-send-email-mlevedahl@gmail.com","threadId":"15100","inReplyTo":"7vej4ii6y8.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] git-submodule.sh - Remove trailing / from URL if found","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2008-08-21T23:54:01Z","receivedAt":"2008-08-21T23:54:01Z","isPatch":true,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"git clone does not complain if a trailing '/' is included in the origin\nURL, but doing so causes resolution of a submodule's URL relative to the\nsuperproject to fail. Trailing /'s are likely when cloning locally using\ntab-completion, so the slash may appear in either superproject or\nsubmodule URL. So, ignore the trailing slash if it already exists in\nthe superproject's URL, and don't record one for the submodule (which\ncould itself have submodules...).\n\nThe problem I'm trying to fix is that a number of folks have\nsuperprojects checked out where the recorded origin URL has a trailing\n/, and a submodule has its origin in a directory sitting right next to\nthe superproject on the server. Thus, we have:\n\n\tsuperproject url = server:/public/super\n\tsubmodoule url = server:/public/sub1\n\nHowever, in the checked out superproject's .git/config\n\n[remote \"origin\"]\n\turl = server:/public/super/\n\nand for similar reasons, the submodule has its URL recorded in .gitmodules as\n[submodule \"sub\"]\n\n\tpath = submodule1\n\turl = ../sub1/\n\nresolve_relative_url gets the submodule's recorded url as $1, which\nthe caller retrieved from .gitmodules, and retrieves the superprojects\norigin from .git/config. So in this case resolve_relative_url has\nthat:\n\n\turl = ../sub1/\n\tremoteurl = server:/public/super/\n\nSo, without any patch, resolve_relative_url computes the submodule's URL as:\n\n\tserver:/public/super/sub1/\n\nrather than\n\n\tserver:/public/sub1\n\nIn summary, it is essential that resolve_relative_url strip the\ntrailing / from the superproject's url before starting, and\nbeneficial if it assures that the result does not contain\na trailing / as the submodule may itself also be a superproject.\n\nSigned-off-by: Mark Levedahl <mlevedahl@gmail.com>\n---\n git-submodule.sh |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 2d57d60..0bc1085 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -36,6 +36,7 @@ resolve_relative_url ()\n \tremoteurl=$(git config \"remote.$remote.url\") ||\n \t\tdie \"remote ($remote) does not have a url defined in .git/config\"\n \turl=\"$1\"\n+\tremoteurl=${remoteurl%/}\n \twhile test -n \"$url\"\n \tdo\n \t\tcase \"$url\" in\n@@ -50,7 +51,7 @@ resolve_relative_url ()\n \t\t\tbreak;;\n \t\tesac\n \tdone\n-\techo \"$remoteurl/$url\"\n+\techo \"$remoteurl\"/\"${url%/}\"\n }\n \n #\n-- \n1.6.0.29.g747a\n"}]}