{"thread":{"id":"36889","subject":"Relative submodule URLs, and forks that haven't forked the submodule","startedAt":"2014-06-11T10:15:39Z","lastAt":"2014-06-12T18:05:43Z","messageCount":4,"participants":["Charles Brossollet","Fredrik Gustafsson","W. Trevor King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"243897","messageId":"E4E16320-06C4-40C5-B561-8DAD720F0946@lltech.fr","threadId":"36889","inReplyTo":null,"subject":"Relative submodule URLs, and forks that haven't forked the submodule","fromName":"Charles Brossollet","fromEmail":"chbrosso@lltech.fr","sentAt":"2014-06-11T10:15:39Z","receivedAt":"2014-06-11T10:15:39Z","isPatch":false,"sender":{"key":"chbrosso@lltech.fr","avatar":null},"body":"Hi,\n\nI'm banging my head on this problem: I have a central repo cloned by SSH, and a fork on the same server. The central remote is origin, and the fork is chbrosso-wip.\n\n$ git remote -v | grep origin\norigin  chbrosso@lltech:/git/lightct.git (fetch)\norigin  chbrosso@lltech:/git/lightct.git (push)\n\n$ git remote -v | grep chbrosso-wip\nchbrosso-wip    chbrosso@lltech:~/prog/git/lightct.git (fetch)\nchbrosso-wip    chbrosso@lltech:~/prog/git/lightct.git (push)\n\nOn a local working copy, fetched my fork and checked out a remote branch out of it. Its remote-tracking branch is on the fork.\n\n$ git branch -vv | grep \\*\n* actor                         d98ec24 [chbrosso-wip/actor] (commit msg)\n\nNow, submodules for this repo have relative URLs. And this is where the problem begins, because the submodule isn't forked, but resides only in origin.\n\nBut this shouldn't cause any problem, right? The docs says that if relative URL are used, they resolve using the origin URL. First issue, it's not the case:\n\n$ cat .gitmodules\n[submodule \"motors\"]\n        path = motors\n        url = ../motors.git\n        branch = master\n$ git submodule init motors\nSubmodule 'motors' (chbrosso@lltech:~/prog/git/motors.git) registered for path 'motors'\n\nHere the submodule is registered on my fork, which doesn't exist, and it's wrong with what the documentation says.\n\nFine, I'll edit the .git/config entry to make it point to origin:\n\n$ git config submodule.motors.url chbrosso@lltech:/git/motors.git\n\n$ git config submodule.motors.url\nchbrosso@lltech:/git/motors.git\n\n$ ssh chbrosso@lltech \"if  [ -d /git/motors.git ]; then echo 'ok'; fi\"\nPassword:\nok\n\nSo the submodule's url is changed, and points to a correct path, let's update so that I can work\n\n$ git submodule update motors\nPassword:\nfatal: '~/prog/git/motors.git' does not appear to be a git repository\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights and the repository exists.\nUnable to fetch in submodule path 'motors'\n\nThat's right, it is still the old url, and I can't have my submodule!\nCan someone explain what's going on? And how can I get my submodule in the working copy?\n\ngit version 1.9.2.msysgit.0 on Windows 7 SP1 64 bit\n\nThanks, \n—- \nCharles\n"},{"id":"243948","messageId":"20140612152556.GH4015@paksenarrion.iveqy.com","threadId":"36889","inReplyTo":"E4E16320-06C4-40C5-B561-8DAD720F0946@lltech.fr","subject":"Re: Relative submodule URLs, and forks that haven't forked the submodule","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2014-06-12T15:25:56Z","receivedAt":"2014-06-12T15:25:56Z","isPatch":false,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"So let me see if I understand you correctly.\n\n\nOn Wed, Jun 11, 2014 at 12:15:39PM +0200, Charles Brossollet wrote:\n> Hi,\n> \n> I'm banging my head on this problem: I have a central repo cloned by SSH, and a fork on the same server. The central remote is origin, and the fork is chbrosso-wip.\n> \n> $ git remote -v | grep origin\n> origin  chbrosso@lltech:/git/lightct.git (fetch)\n> origin  chbrosso@lltech:/git/lightct.git (push)\n> \n> $ git remote -v | grep chbrosso-wip\n> chbrosso-wip    chbrosso@lltech:~/prog/git/lightct.git (fetch)\n> chbrosso-wip    chbrosso@lltech:~/prog/git/lightct.git (push)\n> \n> On a local working copy, fetched my fork and checked out a remote branch out of it. Its remote-tracking branch is on the fork.\n> \n> $ git branch -vv | grep \\*\n> * actor                         d98ec24 [chbrosso-wip/actor] (commit msg)\n> \n> Now, submodules for this repo have relative URLs. And this is where the problem begins, because the submodule isn't forked, but resides only in origin.\n\nFork is not a git thing. It's not a git command and it's not supported\nby git. You can of course easily do a \"fork\" of a git project, but git\nwill be unaware of it beeing a fork.\n\nWhat you're saying is that you've one repository:\n\nlightct.git and one other repository which is a submodule to lightct.git\nat motors.git. Then you've made a copy of lightct.git to an other place\nfor example: /some/other/path/lightct.git and the naturally the\nsubmodule path that's relative will point to /some/other/path/motors.git\nthat doesn't exists, since you haven't copied motors.git\n\n> \n> But this shouldn't cause any problem, right? The docs says that if relative URL are used, they resolve using the origin URL. First issue, it's not the case:\n\nOrgin refers to the repository you cloned from. That is if you did\ngit clone lightct.git my_working_copy\n\nthe origin for my_working_copy would be lightct.git. However if you did\ngit clone /some/other/path/lightct.git my_working_copy\n\nthe origin for my_working_copy would be /some/other/path/lightct.git\n\nSo to me it seems to be correct.\n\n> \n> $ cat .gitmodules\n> [submodule \"motors\"]\n>         path = motors\n>         url = ../motors.git\n>         branch = master\n> $ git submodule init motors\n> Submodule 'motors' (chbrosso@lltech:~/prog/git/motors.git) registered for path 'motors'\n> \n> Here the submodule is registered on my fork, which doesn't exist, and it's wrong with what the documentation says.\n> \n> Fine, I'll edit the .git/config entry to make it point to origin:\n> \n> $ git config submodule.motors.url chbrosso@lltech:/git/motors.git\n> \n> $ git config submodule.motors.url\n> chbrosso@lltech:/git/motors.git\n> \n> $ ssh chbrosso@lltech \"if  [ -d /git/motors.git ]; then echo 'ok'; fi\"\n> Password:\n> ok\n> \n> So the submodule's url is changed, and points to a correct path, let's update so that I can work\n> \n> $ git submodule update motors\n> Password:\n> fatal: '~/prog/git/motors.git' does not appear to be a git repository\n> fatal: Could not read from remote repository.\n> \n> Please make sure you have the correct access rights and the repository exists.\n> Unable to fetch in submodule path 'motors'\n> \n> That's right, it is still the old url, and I can't have my submodule!\n\nHere you change the path to the submodule at\n/some/other/path/lightct.git and then it isn't changed in my_working_copy. How could it? They don't communicate if you don't tell them to.\n\n> Can someone explain what's going on? And how can I get my submodule in the working copy?\n\nEither created a copy of the submodule just as you did with lightct.git\nor use non-relative paths.\n\n-- \nMed vänlig hälsning\nFredrik Gustafsson\n\ntel: 0733-608274\ne-post: iveqy@iveqy.com\n"},{"id":"243949","messageId":"DF027A78-FAC4-4120-9259-1A3D84635BDB@lltech.fr","threadId":"36889","inReplyTo":"20140612152556.GH4015@paksenarrion.iveqy.com","subject":"Re: Relative submodule URLs, and forks that haven't forked the submodule","fromName":"Charles Brossollet","fromEmail":"chbrosso@lltech.fr","sentAt":"2014-06-12T16:05:10Z","receivedAt":"2014-06-12T16:05:10Z","isPatch":false,"sender":{"key":"chbrosso@lltech.fr","avatar":null},"body":"Thanks for taking time to understand, let me make it more clear\n\nLe 12 juin 2014 à 17:25, Fredrik Gustafsson <iveqy@iveqy.com> a écrit :\n\n> So let me see if I understand you correctly.\n> \n> \n> On Wed, Jun 11, 2014 at 12:15:39PM +0200, Charles Brossollet wrote:\n>> Hi,\n>> \n>> I'm banging my head on this problem: I have a central repo cloned by SSH, and a fork on the same server. The central remote is origin, and the fork is chbrosso-wip.\n>> \n>> $ git remote -v | grep origin\n>> origin  chbrosso@lltech:/git/lightct.git (fetch)\n>> origin  chbrosso@lltech:/git/lightct.git (push)\n>> \n>> $ git remote -v | grep chbrosso-wip\n>> chbrosso-wip    chbrosso@lltech:~/prog/git/lightct.git (fetch)\n>> chbrosso-wip    chbrosso@lltech:~/prog/git/lightct.git (push)\n>> \n>> On a local working copy, fetched my fork and checked out a remote branch out of it. Its remote-tracking branch is on the fork.\n>> \n>> $ git branch -vv | grep \\*\n>> * actor                         d98ec24 [chbrosso-wip/actor] (commit msg)\n>> \n>> Now, submodules for this repo have relative URLs. And this is where the problem begins, because the submodule isn't forked, but resides only in origin.\n> \n> Fork is not a git thing. It's not a git command and it's not supported\n> by git. You can of course easily do a \"fork\" of a git project, but git\n> will be unaware of it beeing a fork.\n\nOK, you get it, what I mean by fork here is an independent copy of a repository, at another remote place. \n\n> What you're saying is that you've one repository:\n> \n> lightct.git and one other repository which is a submodule to lightct.git\n> at motors.git. Then you've made a copy of lightct.git to an other place\n> for example: /some/other/path/lightct.git and the naturally the\n> submodule path that's relative will point to /some/other/path/motors.git\n> that doesn't exists, since you haven't copied motors.git\n\nThat's right. Origin is the repository that were original cloned to the working copy, and I have a copy of it, that is in /some/other/path, without motors.git having been copied.\n\nI haven't copied motors.git because I won't modify it, so I still want to refer it… \n\n>> But this shouldn't cause any problem, right? The docs says that if relative URL are used, they resolve using the origin URL. First issue, it's not the case:\n> \n> Orgin refers to the repository you cloned from. That is if you did\n> git clone lightct.git my_working_copy\n> \n> the origin for my_working_copy would be lightct.git. However if you did\n> git clone /some/other/path/lightct.git my_working_copy\n> \n> the origin for my_working_copy would be /some/other/path/lightct.git\n> \n> So to me it seems to be correct.\n\nNo, in the working copy, origin's location isn't changed, it is still the repository I originally (!) cloned from. I added the other remote afterward, and named it chbrosso-wip, not origin. Then, the working copy has two remotes, origin and chbrosso-wip. So if we follow the docs the URL for the submodule shouldn't be set to chbrosso-wip's URL, but this is what is happening.\n\n>>  <snip>\n>> That's right, it is still the old url, and I can't have my submodule!\n> \n> Here you change the path to the submodule at\n> /some/other/path/lightct.git and then it isn't changed in my_working_copy. How could it? They don't communicate if you don't tell them to.\n\nNo, you missed my point, let me explain it a more synthesized way:\n\nThere are 3 repos main, fork, and sub, having the following URLs:\n\n/central/main\n/central/sub\n/user/main\n\nsub is a submodule of main, and referred with a relative URL in .gitmodules.\n\nIn a working copy, cloned from /central/main, thus referred by git as origin, and added /user/main as another remote repository. Fetched from it.\n\nInitially the submodule isn't cloned in the working copy.\n\nThe two problems I'm pointing are:\n\n1. After checkout of a branch that tracks /user/main repo, call git init submodule motors. Git registers it in .git/config with URL /user/sub, while it should be /central/sub according to documentation because origin's URL is at /central.\n\n2. For an obscure reason, changing the url in .git/config to /central/sub and call git submodule update still make git want to clone from /user/sub, and fails. There seems to be no way to tell git the right URL for this submodule, while it should be possible according to the submodule documentation.\n\n> \n>> Can someone explain what's going on? And how can I get my submodule in the working copy?\n> \n> Either created a copy of the submodule just as you did with lightct.git\n> or use non-relative paths.\n> \n> -- \n> Med vänlig hälsning\n> Fredrik Gustafsson\n> \n> tel: 0733-608274\n> e-post: iveqy@iveqy.com\n"},{"id":"244006","messageId":"20140612180543.GA28801@odin.tremily.us","threadId":"36889","inReplyTo":"DF027A78-FAC4-4120-9259-1A3D84635BDB@lltech.fr","subject":"Re: Re: Relative submodule URLs, and forks that haven't forked the submodule","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2014-06-12T18:05:43Z","receivedAt":"2014-06-12T18:05:43Z","isPatch":false,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"On Thu, Jun 12, 2014 at 06:05:10PM +0200, Charles Brossollet wrote:\n> The two problems I'm pointing are:\n> \n> 1. After checkout of a branch that tracks /user/main repo, call git\n>    init submodule motors. Git registers it in .git/config with URL\n>    /user/sub, while it should be /central/sub according to\n>    documentation because origin's URL is at /central.\n\nThe logic for this is in resolve_relative_url, defined in\ngit-submodule.sh.  The remote it uses is calculated using\nget_default_remote, defined in git-parse-remote.sh:\n\n  get_default_remote () {\n    curr_branch=$(git symbolic-ref -q HEAD)\n    curr_branch=\"${curr_branch#refs/heads/}\"\n    origin=$(git config --get \"branch.$curr_branch.remote\")\n    echo ${origin:-origin}\n  }\n\n> 2. For an obscure reason, changing the url in .git/config to\n> /central/sub and call git submodule update still make git want to\n> clone from /user/sub, and fails. There seems to be no way to tell\n> git the right URL for this submodule, while it should be possible\n> according to the submodule documentation.\n\nThis is very surprising to me.  With Git v1.9.1:\n\n* Clone just the superproject, without it's sibling submodule projects:\n\n  $ git clone git://github.com/wking/pygrader.git pg-1\n\n* Clone the isolated superproject, so we'll have broken relative URLs:\n\n  $ git clone pg-1 pg-2\n\n* Initialize a submodule:\n\n  $ git submodule init dep/src/pyassuan\n\n* Fix the broken, expanded-from-relative URL to point back to the\n  original:\n\n  $ git config submodule.dep/src/pyassuan.url git://github.com/wking/pyassuan.git\n\n* Initial, cloning update:\n\n  $ git submodule update\n\nThat all works as expected for me.\n\nCheers,\nTrevor\n\n-- \nThis email may be signed or encrypted with GnuPG (http://www.gnupg.org).\nFor more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy\n"}]}