{"thread":{"id":"27427","subject":"Why does adding an existing repo as a submodule modify .git/config?","startedAt":"2011-05-22T20:02:54Z","lastAt":"2011-05-26T21:35:17Z","messageCount":7,"participants":["Christopher Wilson","Jens Lehmann","Mark Levedahl"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"168455","messageId":"irbq5a$h38$1@dough.gmane.org","threadId":"27427","inReplyTo":null,"subject":"Why does adding an existing repo as a submodule modify .git/config?","fromName":"Christopher Wilson","fromEmail":"cwilson@cdwilson.us","sentAt":"2011-05-22T20:02:54Z","receivedAt":"2011-05-22T20:02:54Z","isPatch":false,"sender":{"key":"cwilson@cdwilson.us","avatar":"https://avatars.githubusercontent.com/u/14631?v=4"},"body":"(I posted this question below on\nhttp://stackoverflow.com/questions/6083357/why-does-adding-an-existing-repo-as-a-submodule-modify-git-config\nand was recommended to ask the mailing list)\n\nIf I add a submodule that does not currently exist, no submodule\ninformation is added to .git/config.\n\n$ mkdir testing\n$ cd testing\n$ git init\n$ git submodule add git@git.server:submodule.git\n$ cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n    ignorecase = true\n\nHowever, if I add a repo that currently exists as a submodule, the url\nis added to .git/config:\n\n$ mkdir testing\n$ cd testing\n$ git init\n$ git clone git@git.server:submodule.git\n$ git submodule add git@git.server:submodule.git\n$ cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n    ignorecase = true\n[submodule \"submodule\"]\n    url = git@git.server:submodule.git\n\nI would have assumed that in both cases, git submodule add would have\nonly modified .gitmodules, and that git submodule init would have\nupdated the project's .git/config.\n\nI'm aware this is intentional behavior\n(https://github.com/git/git/commit/c2f939170c65173076bbd752bb3c764536b3b09b),\nbut I don't understand why.\n\nWhy is .git/config modified in the second case but not the first? Can\nsomebody explain the rational for this behavior?\n"},{"id":"168516","messageId":"4DDAAAD2.1010708@web.de","threadId":"27427","inReplyTo":"irbq5a$h38$1@dough.gmane.org","subject":"Re: Why does adding an existing repo as a submodule modify .git/config?","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2011-05-23T18:43:30Z","receivedAt":"2011-05-23T18:43:30Z","isPatch":false,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 22.05.2011 22:02, schrieb Christopher Wilson:\n> (I posted this question below on\n> http://stackoverflow.com/questions/6083357/why-does-adding-an-existing-repo-as-a-submodule-modify-git-config\n> and was recommended to ask the mailing list)\n> \n> If I add a submodule that does not currently exist, no submodule\n> information is added to .git/config.\n> \n> $ mkdir testing\n> $ cd testing\n> $ git init\n> $ git submodule add git@git.server:submodule.git\n> $ cat .git/config\n> [core]\n>     repositoryformatversion = 0\n>     filemode = true\n>     bare = false\n>     logallrefupdates = true\n>     ignorecase = true\n> \n> However, if I add a repo that currently exists as a submodule, the url\n> is added to .git/config:\n> \n> $ mkdir testing\n> $ cd testing\n> $ git init\n> $ git clone git@git.server:submodule.git\n> $ git submodule add git@git.server:submodule.git\n> $ cat .git/config\n> [core]\n>     repositoryformatversion = 0\n>     filemode = true\n>     bare = false\n>     logallrefupdates = true\n>     ignorecase = true\n> [submodule \"submodule\"]\n>     url = git@git.server:submodule.git\n> \n> I would have assumed that in both cases, git submodule add would have\n> only modified .gitmodules, and that git submodule init would have\n> updated the project's .git/config.\n> \n> I'm aware this is intentional behavior\n> (https://github.com/git/git/commit/c2f939170c65173076bbd752bb3c764536b3b09b),\n> but I don't understand why.\n> \n> Why is .git/config modified in the second case but not the first? Can\n> somebody explain the rational for this behavior?\n\nHmm, this looks like an inconsistency to me too. It would be great\nto hear about the background, so I added Mark to the CC, maybe he\ncan shed some light.\n"},{"id":"168565","messageId":"4DDB0786.5020006@gmail.com","threadId":"27427","inReplyTo":"4DDAAAD2.1010708@web.de","subject":"Re: Why does adding an existing repo as a submodule modify .git/config?","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2011-05-24T01:19:02Z","receivedAt":"2011-05-24T01:19:02Z","isPatch":false,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"On 05/23/2011 02:43 PM, Jens Lehmann wrote:\n> Am 22.05.2011 22:02, schrieb Christopher Wilson:\n>\n> Hmm, this looks like an inconsistency to me too. It would be great\n> to hear about the background, so I added Mark to the CC, maybe he\n> can shed some light.\n>\nI think the comment in c2f939170c651 describes the reasoning well \nenough. (You may disagree with the reasoning, but that is a different \nmatter :^).\n\nMark\n"},{"id":"168570","messageId":"4DDB58D9.2090701@cdwilson.us","threadId":"27427","inReplyTo":"4DDB0786.5020006@gmail.com","subject":"Re: Why does adding an existing repo as a submodule modify .git/config?","fromName":"Christopher Wilson","fromEmail":"cwilson@cdwilson.us","sentAt":"2011-05-24T07:06:01Z","receivedAt":"2011-05-24T07:06:01Z","isPatch":false,"sender":{"key":"cwilson@cdwilson.us","avatar":"https://avatars.githubusercontent.com/u/14631?v=4"},"body":"On 5/23/11 6:19 PM, Mark Levedahl wrote:\n> On 05/23/2011 02:43 PM, Jens Lehmann wrote:\n>> Am 22.05.2011 22:02, schrieb Christopher Wilson:\n>>\n>> Hmm, this looks like an inconsistency to me too. It would be great\n>> to hear about the background, so I added Mark to the CC, maybe he\n>> can shed some light.\n>>\n> I think the comment in c2f939170c651 describes the reasoning well\n> enough. (You may disagree with the reasoning, but that is a different\n> matter :^).\n> \n> Mark\n\nMark, thanks for the reply.  Maybe I'm a bit daft, but I'm still a\nlittle confused by your comment in the commit :)\n\nI've included your commit message below with my questions interlaced.\n\nC: \"When adding a new submodule in place, meaning the user created the\nsubmodule as a git repo in the superproject's tree first, we don't go\nthrough \"git submodule init\" to register the module.\"\n\nQ: Why don't we go through \"git submodule init\" to register the\nsubmodule?  Isn't that the whole point of having a separate \"submodule\ninit\" command, to register the module in .git/config?\n\nC: \"Thus, the submodule's origin repository URL is not stored in\n.git/config, and no subsequent submodule operation will ever do so.\"\n\nI'm not sure this is true.  For example:\n\n$ mkdir testing\n$ cd testing\n$ git init\n$ git clone git@git.server:submodule.git\n$ git submodule add git@git.server:submodule.git\n$ cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n    ignorecase = true\n[submodule \"submodule\"]\n    url = git@git.server:submodule.git\n\n# At this point, I opened up .git/config in an editor and removed the\nentire submodule section.\n\n$ cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n    ignorecase = true\n$ git submodule init\n$ cat .git/config\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n    ignorecase = true\n[submodule \"submodule\"]\n    url = git@git.server:submodule.git\n\nQ: As far as I can tell, a subsequent submodule operation (git submodule\ninit) has stored the submodule's origin repository URL in .git/config.\nCan you elaborate on what you meant by the statement \"no subsequent\nsubmodule operation will ever do so\"?\n\nC: \"In this case, assume the URL the user supplies to \"submodule add\" is\nthe one that should be registered, and do so.\"\n\nQ: Can you elaborate on why a 2 step \"git submodule add\" + \"git\nsubmodule init\" wasn't sufficient?  What is the reason for adding this\nfunctionality into the \"git submodule add\" command, when \"git submodule\ninit\" does the same job?\n\nAgain, sorry if I'm asking dumb questions... :)  Just want to understand\nthe context for your commit.\n"},{"id":"168620","messageId":"4DDC562C.2000204@gmail.com","threadId":"27427","inReplyTo":"4DDB58D9.2090701@cdwilson.us","subject":"Re: Why does adding an existing repo as a submodule modify .git/config?","fromName":"Mark Levedahl","fromEmail":"mlevedahl@gmail.com","sentAt":"2011-05-25T01:06:52Z","receivedAt":"2011-05-25T01:06:52Z","isPatch":false,"sender":{"key":"mdl123@verizon.net","avatar":"https://avatars.githubusercontent.com/u/5302462?v=4"},"body":"On 05/24/2011 03:06 AM, Christopher Wilson wrote:\n>>\n>> Mark\n>\n>\n> Q: Can you elaborate on why a 2 step \"git submodule add\" + \"git\n> submodule init\" wasn't sufficient?  What is the reason for adding this\n> functionality into the \"git submodule add\" command, when \"git submodule\n> init\" does the same job?\n>\n\ngit-submodule.sh has evolved considerably over the last couple of years, \nand the behaviour of submodule-init on an already existing module may \nwell be different.\n\nHowever, while you could then change submodule-add to not register the \nsubmodule, you would now have the condition of having a submodule that \nis checked out in the current tree but *not* registered in .git/config. \nThis is the key: .git/config is modified to include all submodules that \nare checked out in your current tree. If you add a remote submodule, \nthat submodule is not checked out in your current tree so no entry is \ncreated in .git/config, while adding one that is already checked out in \nplace does modify .git/config. I see no inconsistency here.\n\nMark\n"},{"id":"168624","messageId":"BANLkTingA2oRY4i6OnYSz8PGdTRDqXVdFw@mail.gmail.com","threadId":"27427","inReplyTo":"4DDC562C.2000204@gmail.com","subject":"Re: Why does adding an existing repo as a submodule modify .git/config?","fromName":"Christopher Wilson","fromEmail":"cwilson@cdwilson.us","sentAt":"2011-05-25T03:11:34Z","receivedAt":"2011-05-25T03:11:34Z","isPatch":false,"sender":{"key":"cwilson@cdwilson.us","avatar":"https://avatars.githubusercontent.com/u/14631?v=4"},"body":"On Tue, May 24, 2011 at 6:06 PM, Mark Levedahl <mlevedahl@gmail.com> wrote:\n\n> However, while you could then change submodule-add to not register the\n> submodule, you would now have the condition of having a submodule that is\n> checked out in the current tree but *not* registered in .git/config.\n\nIsn't this exactly what \"git submodule add\" currently does for\nsubmodules that are NOT added in place?\n\nFor example:\n\n$ mkdir testing\n$ cd testing\n$ git init\n...\n$ ls\n# nothing in the working tree\n$ git submodule add git@git.server:submodule.git\nCloning into submodule...\nremote: Counting objects: 13, done.\nremote: Compressing objects: 100% (7/7), done.\nremote: Total 13 (delta 2), reused 0 (delta 0)\nReceiving objects: 100% (13/13), done.\nResolving deltas: 100% (2/2), done.\n$ ls\nsubmodule\n$ cat .git/config\n[core]\n   repositoryformatversion = 0\n   filemode = true\n   bare = false\n   logallrefupdates = true\n   ignorecase = true\n$ git status\n# On branch master\n#\n# Initial commit\n#\n# Changes to be committed:\n#   (use \"git rm --cached <file>...\" to unstage)\n#\n#\tnew file:   .gitmodules\n#\tnew file:   submodule\n#\n\nAs you can see, if I create a new repo and check out a remote\nsubmodule, that submodule IS actually checked out in my current tree\nand no entry is created in .git/config.  Although the remote submodule\nhas been added to .gitmodules, it takes \"git submodule init\" to\nactually register it into .git/config:\n\n$ git submodule init\nSubmodule 'submodule' (git@git.server:submodule.git) registered for\npath 'submodule'\n$ cat .git/config\n[core]\n   repositoryformatversion = 0\n   filemode = true\n   bare = false\n   logallrefupdates = true\n   ignorecase = true\n[submodule \"submodule\"]\n   url = git@git.server:submodule.git\n\n> This is the key: .git/config is modified to include all submodules that are checked\n> out in your current tree. If you add a remote submodule, that submodule is\n> not checked out in your current tree so no entry is created in .git/config,\n> while adding one that is already checked out in place does modify\n> .git/config. I see no inconsistency here.\n\nThe inconsistency is that when adding a submodule in place, the\nregistration into .git/config takes place, but when adding a remote\nsubmodule that is not in the working tree, the registration does not\nhappen.  In the second case, don't you end up with exactly what you\nsaid we're trying to avoid, which is \"the condition of having a\nsubmodule that is checked out in the current tree but *not* registered\nin .git/config\"?\n\nChris\n"},{"id":"168830","messageId":"4DDEC795.3030304@web.de","threadId":"27427","inReplyTo":"BANLkTingA2oRY4i6OnYSz8PGdTRDqXVdFw@mail.gmail.com","subject":"Re: Why does adding an existing repo as a submodule modify .git/config?","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2011-05-26T21:35:17Z","receivedAt":"2011-05-26T21:35:17Z","isPatch":false,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 25.05.2011 05:11, schrieb Christopher Wilson:\n> On Tue, May 24, 2011 at 6:06 PM, Mark Levedahl <mlevedahl@gmail.com> wrote:\n> \n>> However, while you could then change submodule-add to not register the\n>> submodule, you would now have the condition of having a submodule that is\n>> checked out in the current tree but *not* registered in .git/config.\n> \n> Isn't this exactly what \"git submodule add\" currently does for\n> submodules that are NOT added in place?\n\nThat is the inconsistency this thread is about. Thanks Christopher for\nbringing that up and to Mark for explaining the rationale for updating\nthe url in .git/config. I really agree with what Mark said there and also\nconcur with Christopher that a \"git submodule add\" should always update\nthe url in .git/config, no matter if it is an already existing repo being\nadded or a freshly cloned one.\n\nBut unfortunately there is more to it than just adding a\n\tgit config submodule.\"$path\".url \"$realrepo\"\nto the module_clone branch in cmd_add() because that makes tests break\nwhere \"git submodule init\" doesn't copy the \"update\" settings into\n.git/config anymore as it already finds an url configured there and\nthinks there is nothing to do. I'm looking into fixing that right now,\nso stay tuned ...\n"}]}