{"thread":{"id":"20097","subject":"Submodule using different repository URLs","startedAt":"2009-07-13T09:57:24Z","lastAt":"2009-07-13T13:33:10Z","messageCount":8,"participants":["Peter Voss","Santi Béjar","Johan Herland"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"117895","messageId":"5BE6F3DC-4B00-4D84-8D0E-41057735483F@petervoss.org","threadId":"20097","inReplyTo":null,"subject":"Submodule using different repository URLs","fromName":"Peter Voss","fromEmail":"info@petervoss.org","sentAt":"2009-07-13T09:57:24Z","receivedAt":"2009-07-13T09:57:24Z","isPatch":false,"sender":{"key":"info@petervoss.org","avatar":"https://gravatar.com/avatar/aa67c8386a6d7ca6b5cb0d7af647c01f05986f9789213c90be3d0d5705c9a104?d=mp&s=160"},"body":"Hi,\n\nI want to use the git submodule feature to move part of my code to a  \ndifferent repository at github.\n\nThe issue is that developers should use different repository URLs for  \nthe submodule depending on whether they have commit rights or not.\n\nAt the beginning I was using the public URL to set-up the submodule:\ngit submodule add git://github.com/x/mymodule.git mymodule\n\nThe issue is that some developers are working behind a firewall that  \nblocks the git protocol. These could only use the git@github.com:x/ \nmymodule.git URL to get access.\nBut other developers can only go through the public URL git:// \ngithub.com/x/mymodule.git. So whatever I use it won't work for  \neverybody.\n\nWhat's the best way to deal with that? Could I set-up different  \nrepository URLs for one and the same submodule and use which one is  \nappropriate?\n\nThanks,\n--Peter\n"},{"id":"117897","messageId":"adf1fd3d0907130320s726bb80at58d454c830c7d5be@mail.gmail.com","threadId":"20097","inReplyTo":"5BE6F3DC-4B00-4D84-8D0E-41057735483F@petervoss.org","subject":"Re: Submodule using different repository URLs","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-07-13T10:20:59Z","receivedAt":"2009-07-13T10:20:59Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/7/13 Peter Voss <info@petervoss.org>:\n> Hi,\n>\n> I want to use the git submodule feature to move part of my code to a\n> different repository at github.\n>\n> The issue is that developers should use different repository URLs for the\n> submodule depending on whether they have commit rights or not.\n>\n> At the beginning I was using the public URL to set-up the submodule:\n> git submodule add git://github.com/x/mymodule.git mymodule\n>\n> The issue is that some developers are working behind a firewall that blocks\n> the git protocol. These could only use the git@github.com:x/mymodule.git URL\n> to get access.\n> But other developers can only go through the public URL\n> git://github.com/x/mymodule.git. So whatever I use it won't work for\n> everybody.\n>\n> What's the best way to deal with that? Could I set-up different repository\n> URLs for one and the same submodule and use which one is appropriate?\n\nAfter the \"git submodule init\" you can customize the url. From \"man\ngit-submodule\":\n\ninit::\n        Initialize the submodules, i.e. register each submodule name\n        and url found in .gitmodules into .git/config.\n        The key used in .git/config is `submodule.$name.url`.\n        This command does not alter existing information in .git/config.\n        You can then customize the submodule clone URLs in .git/config\n        for your local setup and proceed to 'git submodule update';\n        you can also just use 'git submodule update --init' without\n        the explicit 'init' step if you do not intend to customize\n        any submodule locations.\n\nYou can also use the config url.\"<actual url base>\".insteadOf = <other\nurl base>.\nSee the git-pull manpage for examples.\n\nHTH,\nSanti\n"},{"id":"117898","messageId":"200907131259.42313.johan@herland.net","threadId":"20097","inReplyTo":"5BE6F3DC-4B00-4D84-8D0E-41057735483F@petervoss.org","subject":"Re: Submodule using different repository URLs","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2009-07-13T10:59:42Z","receivedAt":"2009-07-13T10:59:42Z","isPatch":false,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Monday 13 July 2009, Peter Voss wrote:\n> Hi,\n>\n> I want to use the git submodule feature to move part of my code to a\n> different repository at github.\n>\n> The issue is that developers should use different repository URLs for\n> the submodule depending on whether they have commit rights or not.\n>\n> At the beginning I was using the public URL to set-up the submodule:\n> git submodule add git://github.com/x/mymodule.git mymodule\n>\n> The issue is that some developers are working behind a firewall that\n> blocks the git protocol. These could only use the git@github.com:x/\n> mymodule.git URL to get access.\n> But other developers can only go through the public URL git://\n> github.com/x/mymodule.git. So whatever I use it won't work for\n> everybody.\n>\n> What's the best way to deal with that? Could I set-up different\n> repository URLs for one and the same submodule and use which one is\n> appropriate?\n\nYou might be able to pull this off using relative submodule URLs. If the \nsubmodule URLs in .gitmodules are relative (i.e. ../foo.git or \nsimilar), they will be resolved to absolute URLs using the origin URL \nof the super-repo. I.e. if you cloned the super-repo from \ngit://github.com/x/mymodule.git, the ../foo.git submodule will be \ncloned from git://github.com/x/foo.git, and if you cloned from \ngit@github.com:x/mymodule.git, the submodule will be cloned from \ngit@github.com:x/foo.git.\n\nHope this helps,\n\n\nHave fun! :)\n\n...Johan\n\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"117900","messageId":"64652870-CF95-49A7-920A-0F9A6C202B40@petervoss.org","threadId":"20097","inReplyTo":"200907131259.42313.johan@herland.net","subject":"Re: Submodule using different repository URLs","fromName":"Peter Voss","fromEmail":"info@petervoss.org","sentAt":"2009-07-13T11:51:56Z","receivedAt":"2009-07-13T11:51:56Z","isPatch":false,"sender":{"key":"info@petervoss.org","avatar":"https://gravatar.com/avatar/aa67c8386a6d7ca6b5cb0d7af647c01f05986f9789213c90be3d0d5705c9a104?d=mp&s=160"},"body":"Hi Johan,\n\nOn 13.07.2009, at 12:59, Johan Herland wrote:\n\n> On Monday 13 July 2009, Peter Voss wrote:\n>> Hi,\n>>\n>> I want to use the git submodule feature to move part of my code to a\n>> different repository at github.\n>>\n>> The issue is that developers should use different repository URLs for\n>> the submodule depending on whether they have commit rights or not.\n>>\n>> At the beginning I was using the public URL to set-up the submodule:\n>> git submodule add git://github.com/x/mymodule.git mymodule\n>>\n>> The issue is that some developers are working behind a firewall that\n>> blocks the git protocol. These could only use the git@github.com:x/\n>> mymodule.git URL to get access.\n>> But other developers can only go through the public URL git://\n>> github.com/x/mymodule.git. So whatever I use it won't work for\n>> everybody.\n>>\n>> What's the best way to deal with that? Could I set-up different\n>> repository URLs for one and the same submodule and use which one is\n>> appropriate?\n>\n> You might be able to pull this off using relative submodule URLs. If  \n> the\n> submodule URLs in .gitmodules are relative (i.e. ../foo.git or\n> similar), they will be resolved to absolute URLs using the origin URL\n> of the super-repo. I.e. if you cloned the super-repo from\n> git://github.com/x/mymodule.git, the ../foo.git submodule will be\n> cloned from git://github.com/x/foo.git, and if you cloned from\n> git@github.com:x/mymodule.git, the submodule will be cloned from\n> git@github.com:x/foo.git.\n\nThat's a good hint. Unfortunately I can't use this to go up 2  \ndirectories. I.e. I can't get from\ngit@github.com:xxx/mymodule.git\nto\ngit@github.com:yyy/foo.git\n\nUsing the relative URL ../../yyy/foo.git leads to the result:\nClone of 'git@github.com:xxx/yyy/foo.git' into submodule path 'foo'  \nfailed\n\nSo I basically cannot replace the xxx part.\n\nAnyway, thanks for the hint.\n--Peter\n\n> Hope this helps,\n>\n>\n> Have fun! :)\n>\n> ...Johan\n>\n>\n> -- \n> Johan Herland, <johan@herland.net>\n> www.herland.net\n"},{"id":"117901","messageId":"EDAD14B2-414A-436B-BA85-CBD9A13B2B87@petervoss.org","threadId":"20097","inReplyTo":"adf1fd3d0907130320s726bb80at58d454c830c7d5be@mail.gmail.com","subject":"Re: Submodule using different repository URLs","fromName":"Peter Voss","fromEmail":"info@petervoss.org","sentAt":"2009-07-13T12:04:49Z","receivedAt":"2009-07-13T12:04:49Z","isPatch":false,"sender":{"key":"info@petervoss.org","avatar":"https://gravatar.com/avatar/aa67c8386a6d7ca6b5cb0d7af647c01f05986f9789213c90be3d0d5705c9a104?d=mp&s=160"},"body":"Hi Santi,\n\nOn 13.07.2009, at 12:20, Santi Béjar wrote:\n\n> 2009/7/13 Peter Voss <info@petervoss.org>:\n>> Hi,\n>>\n>> I want to use the git submodule feature to move part of my code to a\n>> different repository at github.\n>>\n>> The issue is that developers should use different repository URLs  \n>> for the\n>> submodule depending on whether they have commit rights or not.\n>>\n>> At the beginning I was using the public URL to set-up the submodule:\n>> git submodule add git://github.com/x/mymodule.git mymodule\n>>\n>> The issue is that some developers are working behind a firewall  \n>> that blocks\n>> the git protocol. These could only use the git@github.com:x/ \n>> mymodule.git URL\n>> to get access.\n>> But other developers can only go through the public URL\n>> git://github.com/x/mymodule.git. So whatever I use it won't work for\n>> everybody.\n>>\n>> What's the best way to deal with that? Could I set-up different  \n>> repository\n>> URLs for one and the same submodule and use which one is appropriate?\n>\n> After the \"git submodule init\" you can customize the url. From \"man\n> git-submodule\":\n>\n> init::\n>        Initialize the submodules, i.e. register each submodule name\n>        and url found in .gitmodules into .git/config.\n>        The key used in .git/config is `submodule.$name.url`.\n>        This command does not alter existing information in .git/ \n> config.\n>        You can then customize the submodule clone URLs in .git/config\n>        for your local setup and proceed to 'git submodule update';\n>        you can also just use 'git submodule update --init' without\n>        the explicit 'init' step if you do not intend to customize\n>        any submodule locations.\n>\n> You can also use the config url.\"<actual url base>\".insteadOf = <other\n> url base>.\n> See the git-pull manpage for examples.\n\nI didn't get the insteadOf config running (maybe I have to update to a  \nmore recent version of git). But modifying the URL in .git/config  \nshould be a doable approach for us. In order to add the insteadOf  \nsection we would have to edit the .git/config file as well, so that  \ndoesn't seem to be much better.\n\nThanks for your help,\n--Peter\n\n> HTH,\n> Santi\n"},{"id":"117902","messageId":"200907131428.43652.johan@herland.net","threadId":"20097","inReplyTo":"64652870-CF95-49A7-920A-0F9A6C202B40@petervoss.org","subject":"Re: Submodule using different repository URLs","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2009-07-13T12:28:43Z","receivedAt":"2009-07-13T12:28:43Z","isPatch":false,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Monday 13 July 2009, Peter Voss wrote:\n> On 13.07.2009, at 12:59, Johan Herland wrote:\n> > You might be able to pull this off using relative submodule URLs.\n>\n> That's a good hint. Unfortunately I can't use this to go up 2\n> directories. I.e. I can't get from\n> git@github.com:xxx/mymodule.git\n> to\n> git@github.com:yyy/foo.git\n>\n> Using the relative URL ../../yyy/foo.git leads to the result:\n> Clone of 'git@github.com:xxx/yyy/foo.git' into submodule path 'foo'\n> failed\n>\n> So I basically cannot replace the xxx part.\n\nThis is due to a small bug in git-submodule.sh. In the \nresolve_relative_url() function, when repeatedly unwrapping '../'s from \n$url in the while loop, the line remoteurl=\"${remoteurl%/*}\" removes \neverything _after_ the last slash, which does not work for the \ngit@github.com:xxx part of your URL.\n\nThis should be relatively easy to fix, although maybe not as \nstraightforwardly trivial as it might seem at first sight.\n\nI don't have the time to look into this now, so feel free to take a stab \nat it.\n\n\nHave fun! :)\n\n...Johan\n\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"117903","messageId":"200907131443.25719.johan@herland.net","threadId":"20097","inReplyTo":"200907131428.43652.johan@herland.net","subject":"Re: Submodule using different repository URLs","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2009-07-13T12:43:25Z","receivedAt":"2009-07-13T12:43:25Z","isPatch":false,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Monday 13 July 2009, Johan Herland wrote:\n> On Monday 13 July 2009, Peter Voss wrote:\n> > On 13.07.2009, at 12:59, Johan Herland wrote:\n> > > You might be able to pull this off using relative submodule URLs.\n> >\n> > That's a good hint. Unfortunately I can't use this to go up 2\n> > directories. I.e. I can't get from\n> > git@github.com:xxx/mymodule.git\n> > to\n> > git@github.com:yyy/foo.git\n> >\n> > Using the relative URL ../../yyy/foo.git leads to the result:\n> > Clone of 'git@github.com:xxx/yyy/foo.git' into submodule path 'foo'\n> > failed\n> >\n> > So I basically cannot replace the xxx part.\n>\n> This is due to a small bug in git-submodule.sh. In the\n> resolve_relative_url() function, when repeatedly unwrapping '../'s\n> from $url in the while loop, the line remoteurl=\"${remoteurl%/*}\"\n> removes everything _after_ the last slash, which does not work for\n> the git@github.com:xxx part of your URL.\n>\n> This should be relatively easy to fix, although maybe not as\n> straightforwardly trivial as it might seem at first sight.\n>\n> I don't have the time to look into this now, so feel free to take a\n> stab at it.\n\nHere's a first stab at it (TOTALLY UNTESTED). Obviously it needs a\ntestcase (typically in t7400-submodule-basic.sh) as well.\n\n\nHave fun! :)\n\n...Johan\n\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ebed711..7d8f7a7 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -27,12 +27,19 @@ resolve_relative_url ()\n \t\tdie \"remote ($remote) does not have a url defined in .git/config\"\n \turl=\"$1\"\n \tremoteurl=${remoteurl%/}\n+\tsep=\"/\"\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\tnewremoteurl=\"${remoteurl%/*}\"\n+\t\t\tif test \"$newremoteurl\" = \"$remoteurl\" -a \"$sep\" = \"/\"\n+\t\t\tthen\n+\t\t\t\tnewremoteurl=\"${remoteurl%:*}\"\n+\t\t\t\tsep=\":\"\n+\t\t\tfi\n+\t\t\tremoteurl=\"$newremoteurl\"\n \t\t\t;;\n \t\t./*)\n \t\t\turl=\"${url#./}\"\n@@ -41,7 +48,7 @@ resolve_relative_url ()\n \t\t\tbreak;;\n \t\tesac\n \tdone\n-\techo \"$remoteurl/${url%/}\"\n+\techo \"$remoteurl$sep${url%/}\"\n }\n \n #\n\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"117904","messageId":"9B026405-27EB-4D48-8D08-461D213453C3@petervoss.org","threadId":"20097","inReplyTo":"200907131443.25719.johan@herland.net","subject":"Re: Submodule using different repository URLs","fromName":"Peter Voss","fromEmail":"info@petervoss.org","sentAt":"2009-07-13T13:33:10Z","receivedAt":"2009-07-13T13:33:10Z","isPatch":false,"sender":{"key":"info@petervoss.org","avatar":"https://gravatar.com/avatar/aa67c8386a6d7ca6b5cb0d7af647c01f05986f9789213c90be3d0d5705c9a104?d=mp&s=160"},"body":"Hi Johan,\n\nOn 13.07.2009, at 14:43, Johan Herland wrote:\n\n> On Monday 13 July 2009, Johan Herland wrote:\n>> On Monday 13 July 2009, Peter Voss wrote:\n>>> On 13.07.2009, at 12:59, Johan Herland wrote:\n>>>> You might be able to pull this off using relative submodule URLs.\n>>>\n>>> That's a good hint. Unfortunately I can't use this to go up 2\n>>> directories. I.e. I can't get from\n>>> git@github.com:xxx/mymodule.git\n>>> to\n>>> git@github.com:yyy/foo.git\n>>>\n>>> Using the relative URL ../../yyy/foo.git leads to the result:\n>>> Clone of 'git@github.com:xxx/yyy/foo.git' into submodule path 'foo'\n>>> failed\n>>>\n>>> So I basically cannot replace the xxx part.\n>>\n>> This is due to a small bug in git-submodule.sh. In the\n>> resolve_relative_url() function, when repeatedly unwrapping '../'s\n>> from $url in the while loop, the line remoteurl=\"${remoteurl%/*}\"\n>> removes everything _after_ the last slash, which does not work for\n>> the git@github.com:xxx part of your URL.\n>>\n>> This should be relatively easy to fix, although maybe not as\n>> straightforwardly trivial as it might seem at first sight.\n>>\n>> I don't have the time to look into this now, so feel free to take a\n>> stab at it.\n>\n> Here's a first stab at it (TOTALLY UNTESTED). Obviously it needs a\n> testcase (typically in t7400-submodule-basic.sh) as well.\n\nAnd I thought you didn't have time. ;-) Thanks for this patch. I will  \ntest this out tomorrow.\n\nThanks,\n--Peter\n\n>\n>\n> Have fun! :)\n>\n> ...Johan\n>\n>\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index ebed711..7d8f7a7 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -27,12 +27,19 @@ resolve_relative_url ()\n> \t\tdie \"remote ($remote) does not have a url defined in .git/config\"\n> \turl=\"$1\"\n> \tremoteurl=${remoteurl%/}\n> +\tsep=\"/\"\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\tnewremoteurl=\"${remoteurl%/*}\"\n> +\t\t\tif test \"$newremoteurl\" = \"$remoteurl\" -a \"$sep\" = \"/\"\n> +\t\t\tthen\n> +\t\t\t\tnewremoteurl=\"${remoteurl%:*}\"\n> +\t\t\t\tsep=\":\"\n> +\t\t\tfi\n> +\t\t\tremoteurl=\"$newremoteurl\"\n> \t\t\t;;\n> \t\t./*)\n> \t\t\turl=\"${url#./}\"\n> @@ -41,7 +48,7 @@ resolve_relative_url ()\n> \t\t\tbreak;;\n> \t\tesac\n> \tdone\n> -\techo \"$remoteurl/${url%/}\"\n> +\techo \"$remoteurl$sep${url%/}\"\n> }\n>\n> #\n>\n>\n> -- \n> Johan Herland, <johan@herland.net>\n> www.herland.net\n"}]}