{"thread":{"id":"31064","subject":"[PATCH] Solve git-submodule issues with detached work trees","startedAt":"2012-07-22T14:49:44Z","lastAt":"2012-07-23T23:42:01Z","messageCount":11,"participants":["Daniel Graña","Junio C Hamano","Jens Lehmann","Richard Hartmann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"195444","messageId":"CAHCkQtNfz8Kbn810LgXEQ_rkyk4qn5amGgHQsv2uR6H38sTSrg@mail.gmail.com","threadId":"31064","inReplyTo":null,"subject":"[PATCH] Solve git-submodule issues with detached work trees","fromName":"Daniel Graña","fromEmail":"dangra@gmail.com","sentAt":"2012-07-22T14:49:44Z","receivedAt":"2012-07-22T14:49:44Z","isPatch":true,"sender":{"key":"dangra@gmail.com","avatar":"https://avatars.githubusercontent.com/u/37369?v=4"},"body":"A common way to track dotfiles with git is using GIT_DIR and\nGIT_WORK_TREE to move repository out of ~/.git with something like:\n\n    git init --bare ~/.dotfiles\n    alias dotfiles=\"GIT_DIR=~/.dotfiles GIT_WORK_TREE=~ git\"\n\n    dotfiles add ~/.bashrc\n    dotfiles commit -a -m \"add my bashrc\"\n    ...\n\nbut git-submodule complains when trying to add submodules:\n\n    dotfiles submodule add http://path.to/submodule\n    fatal: working tree '/home/user' already exists.\n\n    git --git-dir ~/.dotfiles submodule add http://path.to/submodule\n    fatal: /usr/lib/git-core/git-submodule cannot be used without a\nworking tree.\n\nSigned-off-by: Daniel Graña <dangra@gmail.com>\n---\n git-submodule.sh                       |    7 +++-\n t/t7409-submodule-detached-worktree.sh |   61 ++++++++++++++++++++++++++++++++\n 2 files changed, 66 insertions(+), 2 deletions(-)\n create mode 100755 t/t7409-submodule-detached-worktree.sh\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5629d87..88ee4ea 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -181,8 +181,11 @@ module_clone()\n \t\trm -f \"$gitdir/index\"\n \telse\n \t\tmkdir -p \"$gitdir_base\"\n-\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n-\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\" ||\n+\t\t(\n+\t\t\tclear_local_git_env\n+\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n+\t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n+\t\t) ||\n \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path\n'\\$sm_path' failed\")\"\n \tfi\n\ndiff --git a/t/t7409-submodule-detached-worktree.sh\nb/t/t7409-submodule-detached-worktree.sh\nnew file mode 100755\nindex 0000000..db75642\n--- /dev/null\n+++ b/t/t7409-submodule-detached-worktree.sh\n@@ -0,0 +1,61 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2012 Daniel Graña\n+#\n+\n+test_description='Test submodules on detached working tree\n+\n+This test verifies that \"git submodule\" initialization, update and\naddition works\n+on detahced working trees\n+'\n+\n+TEST_NO_CREATE_REPO=1\n+. ./test-lib.sh\n+\n+test_expect_success 'submodule on detached working tree' '\n+\tgit init --bare remote &&\n+\ttest_create_repo bundle1 &&\n+\t(cd bundle1 && test_commit \"shoot\") &&\n+\tmkdir home &&\n+\t(\n+\t\tcd home &&\n+\t\texport GIT_WORK_TREE=\"$(pwd)\" GIT_DIR=\"$(pwd)/.dotfiles\" &&\n+\t\tgit clone --bare ../remote .dotfiles &&\n+\t\tgit submodule add ../bundle1 .vim/bundle/sogood &&\n+\t\ttest_commit \"sogood\" &&\n+\t\tgit push origin master\n+\t) &&\n+\tmkdir home2 &&\n+\t(\n+\t\tcd home2 &&\n+\t\texport GIT_WORK_TREE=\"$(pwd)\" GIT_DIR=\"$(pwd)/.dotfiles\" &&\n+\t\tgit clone --bare ../remote .dotfiles &&\n+\t\tgit submodule update --init\n+\t)\n+'\n+\n+test_expect_success 'submodule on detached working pointed by core.worktree' '\n+\tmkdir home3 &&\n+\t(\n+\t\tcd home3 &&\n+\t\texport GIT_DIR=\"$(pwd)/.dotfiles\" &&\n+\t\tgit clone --bare ../remote \"$GIT_DIR\" &&\n+\t\tgit config core.bare false &&\n+\t\tgit config core.worktree .. &&\n+\t\tgit submodule add ../bundle1 .vim/bundle/dupe &&\n+\t\ttest_commit \"dupe\" &&\n+\t\tgit push origin master\n+\t) &&\n+\t(\n+\t\tcd home &&\n+\t\texport GIT_DIR=\"$(pwd)/.dotfiles\" &&\n+\t\tgit config core.bare false &&\n+\t\tgit config core.worktree .. &&\n+\t\tgit pull &&\n+\t\tgit submodule update &&\n+\t\tgit submodule status &&\n+\t\ttest -d .vim/bundle/dupe\n+\t)\n+'\n+\n+test_done\n-- \n1.7.5.4\n"},{"id":"195491","messageId":"7vsjcjnjvj.fsf@alter.siamese.dyndns.org","threadId":"31064","inReplyTo":"CAHCkQtNfz8Kbn810LgXEQ_rkyk4qn5amGgHQsv2uR6H38sTSrg@mail.gmail.com","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-23T05:09:52Z","receivedAt":"2012-07-23T05:09:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Graña <dangra@gmail.com> writes:\n\n> A common way to track dotfiles with git is using GIT_DIR and\n> GIT_WORK_TREE to move repository out of ~/.git with something like:\n>\n>     git init --bare ~/.dotfiles\n>     alias dotfiles=\"GIT_DIR=~/.dotfiles GIT_WORK_TREE=~ git\"\n>\n>     dotfiles add ~/.bashrc\n>     dotfiles commit -a -m \"add my bashrc\"\n>     ...\n>\n> but git-submodule complains when trying to add submodules:\n>\n>     dotfiles submodule add http://path.to/submodule\n>     fatal: working tree '/home/user' already exists.\n>\n>     git --git-dir ~/.dotfiles submodule add http://path.to/submodule\n>     fatal: /usr/lib/git-core/git-submodule cannot be used without a\n> working tree.\n>\n> Signed-off-by: Daniel Graña <dangra@gmail.com>\n> ---\n\nI think this is in line with what we discussed earlier on list when\nthe interaction between GIT_DIR/GIT_WORK_TREE and submodules came up\nthe last time.  Jens?\n\n>  git-submodule.sh                       |    7 +++-\n>  t/t7409-submodule-detached-worktree.sh |   61 ++++++++++++++++++++++++++++++++\n>  2 files changed, 66 insertions(+), 2 deletions(-)\n>  create mode 100755 t/t7409-submodule-detached-worktree.sh\n>\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 5629d87..88ee4ea 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -181,8 +181,11 @@ module_clone()\n>  \t\trm -f \"$gitdir/index\"\n>  \telse\n>  \t\tmkdir -p \"$gitdir_base\"\n> -\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n> -\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\" ||\n> +\t\t(\n> +\t\t\tclear_local_git_env\n> +\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n> +\t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n> +\t\t) ||\n>  \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path\n> '\\$sm_path' failed\")\"\n\nLine-wrapped broken patch?\n\n>  \tfi\n>\n> diff --git a/t/t7409-submodule-detached-worktree.sh\n> b/t/t7409-submodule-detached-worktree.sh\n> new file mode 100755\n> index 0000000..db75642\n> --- /dev/null\n> +++ b/t/t7409-submodule-detached-worktree.sh\n> @@ -0,0 +1,61 @@\n> +#!/bin/sh\n> +#\n> +# Copyright (c) 2012 Daniel Graña\n> +#\n> +\n> +test_description='Test submodules on detached working tree\n> +\n> +This test verifies that \"git submodule\" initialization, update and\n> addition works\n\nLine-wrapped broken patch?\n\n> +on detahced working trees\n> +'\n> +\n> +TEST_NO_CREATE_REPO=1\n> +. ./test-lib.sh\n> +\n> +test_expect_success 'submodule on detached working tree' '\n> +\tgit init --bare remote &&\n> +\ttest_create_repo bundle1 &&\n> +\t(cd bundle1 && test_commit \"shoot\") &&\n> +\tmkdir home &&\n> +\t(\n> +\t\tcd home &&\n> +\t\texport GIT_WORK_TREE=\"$(pwd)\" GIT_DIR=\"$(pwd)/.dotfiles\" &&\n> +\t\tgit clone --bare ../remote .dotfiles &&\n> +\t\tgit submodule add ../bundle1 .vim/bundle/sogood &&\n> +\t\ttest_commit \"sogood\" &&\n> +\t\tgit push origin master\n> +\t) &&\n\nDon't you want to verify not just commands succeed, but leave a\nreasonable result, e.g. by running \"git rev-parse HEAD\" in \"remote\"\nand comparing the output with \"git rev-parse HEAD\" in .dotfiles, or\nsomething?\n\n> +\tmkdir home2 &&\n> +\t(\n> +\t\tcd home2 &&\n> +\t\texport GIT_WORK_TREE=\"$(pwd)\" GIT_DIR=\"$(pwd)/.dotfiles\" &&\n> +\t\tgit clone --bare ../remote .dotfiles &&\n> +\t\tgit submodule update --init\n\nLikewise.  What state, other than \"submodule update --init\" does not\nbarf, do you expect to see?\n\n> +\t)\n> +'\n> +\n> +test_expect_success 'submodule on detached working pointed by core.worktree' '\n> +\tmkdir home3 &&\n> +\t(\n> +\t\tcd home3 &&\n> +\t\texport GIT_DIR=\"$(pwd)/.dotfiles\" &&\n> +\t\tgit clone --bare ../remote \"$GIT_DIR\" &&\n> +\t\tgit config core.bare false &&\n> +\t\tgit config core.worktree .. &&\n> +\t\tgit submodule add ../bundle1 .vim/bundle/dupe &&\n> +\t\ttest_commit \"dupe\" &&\n> +\t\tgit push origin master\n\nLikewise.\n\n> +\t) &&\n> +\t(\n> +\t\tcd home &&\n> +\t\texport GIT_DIR=\"$(pwd)/.dotfiles\" &&\n> +\t\tgit config core.bare false &&\n> +\t\tgit config core.worktree .. &&\n> +\t\tgit pull &&\n> +\t\tgit submodule update &&\n> +\t\tgit submodule status &&\n> +\t\ttest -d .vim/bundle/dupe\n\nLikewise.  Is there something you want to verify in the branches in\nthe submodule and its working tree, other than the existence of that\ndirectory?\n\n> +\t)\n> +'\n> +\n> +test_done\n"},{"id":"195535","messageId":"500D8C30.9010807@web.de","threadId":"31064","inReplyTo":"7vsjcjnjvj.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-07-23T17:38:56Z","receivedAt":"2012-07-23T17:38:56Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 23.07.2012 07:09, schrieb Junio C Hamano:\n> Daniel Graña <dangra@gmail.com> writes:\n> \n>> A common way to track dotfiles with git is using GIT_DIR and\n>> GIT_WORK_TREE to move repository out of ~/.git with something like:\n>>\n>>     git init --bare ~/.dotfiles\n>>     alias dotfiles=\"GIT_DIR=~/.dotfiles GIT_WORK_TREE=~ git\"\n>>\n>>     dotfiles add ~/.bashrc\n>>     dotfiles commit -a -m \"add my bashrc\"\n>>     ...\n>>\n>> but git-submodule complains when trying to add submodules:\n>>\n>>     dotfiles submodule add http://path.to/submodule\n>>     fatal: working tree '/home/user' already exists.\n>>\n>>     git --git-dir ~/.dotfiles submodule add http://path.to/submodule\n>>     fatal: /usr/lib/git-core/git-submodule cannot be used without a\n>> working tree.\n>>\n>> Signed-off-by: Daniel Graña <dangra@gmail.com>\n>> ---\n> \n> I think this is in line with what we discussed earlier on list when\n> the interaction between GIT_DIR/GIT_WORK_TREE and submodules came up\n> the last time.  Jens?\n\nYes, I think this is the only way submodules in current git can\nbe used with the GIT_DIR and GIT_WORK_TREE environment variables:\nset them when adding or initializing the submodule and always use\nthe same settings when accessing them later. Daniel's dotfile\nalias achieves exactly that, so his fix looks good. But I agree\nthe tests should be improved as you already pointed out.\n"},{"id":"195538","messageId":"7v7gtumj88.fsf@alter.siamese.dyndns.org","threadId":"31064","inReplyTo":"500D8C30.9010807@web.de","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-23T18:21:27Z","receivedAt":"2012-07-23T18:21:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jens Lehmann <Jens.Lehmann@web.de> writes:\n\n> Am 23.07.2012 07:09, schrieb Junio C Hamano:\n>> Daniel Graña <dangra@gmail.com> writes:\n>> \n>>> A common way to track dotfiles with git is using GIT_DIR and\n>>> GIT_WORK_TREE to move repository out of ~/.git with something like:\n>>>\n>>>     git init --bare ~/.dotfiles\n>>>     alias dotfiles=\"GIT_DIR=~/.dotfiles GIT_WORK_TREE=~ git\"\n>>>\n>>>     dotfiles add ~/.bashrc\n>>>     dotfiles commit -a -m \"add my bashrc\"\n>>>     ...\n>>>\n>>> but git-submodule complains when trying to add submodules:\n>>>\n>>>     dotfiles submodule add http://path.to/submodule\n>>>     fatal: working tree '/home/user' already exists.\n>>>\n>>>     git --git-dir ~/.dotfiles submodule add http://path.to/submodule\n>>>     fatal: /usr/lib/git-core/git-submodule cannot be used without a\n>>> working tree.\n>>>\n>>> Signed-off-by: Daniel Graña <dangra@gmail.com>\n>>> ---\n>> \n>> I think this is in line with what we discussed earlier on list when\n>> the interaction between GIT_DIR/GIT_WORK_TREE and submodules came up\n>> the last time.  Jens?\n>\n> Yes, I think this is the only way submodules in current git can\n> be used with the GIT_DIR and GIT_WORK_TREE environment variables:\n> set them when adding or initializing the submodule and always use\n> the same settings when accessing them later. Daniel's dotfile\n> alias achieves exactly that, so his fix looks good. But I agree\n> the tests should be improved as you already pointed out.\n\nThanks for a quick review.  The \"the only way ... in current git can\nbe used\" part makes it sound as if it is a somewhat suboptimal ugly\nworkaround, but if that is what you meant, what is a more optimal\nand less ugly way that you have in mind?\n\nIf you want to move .git out of way with GIT_DIR and if you want to\nsit somewhere different from the top of your working tree, you must\nuse GIT_WORK_TREE (or core.worktree) to tell where the top resides,\nwhether your project use submodules or not, so I do not think it is\nan ugly workaround but is the one true way to use such a dismembered\nlayout, I would think.\n"},{"id":"195539","messageId":"CAHCkQtOCrCaF01fu-LS5jaTbiD7mxmWu0Mi5Dh1YCvcjdUkqLg@mail.gmail.com","threadId":"31064","inReplyTo":"500D8C30.9010807@web.de","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Daniel Graña","fromEmail":"dangra@gmail.com","sentAt":"2012-07-23T18:22:57Z","receivedAt":"2012-07-23T18:22:57Z","isPatch":true,"sender":{"key":"dangra@gmail.com","avatar":"https://avatars.githubusercontent.com/u/37369?v=4"},"body":"On Mon, Jul 23, 2012 at 2:38 PM, Jens Lehmann <Jens.Lehmann@web.de> wrote:\n> Am 23.07.2012 07:09, schrieb Junio C Hamano:\n>> Daniel Graña <dangra@gmail.com> writes:\n>>\n>>> A common way to track dotfiles with git is using GIT_DIR and\n>>> GIT_WORK_TREE to move repository out of ~/.git with something like:\n>>>\n>>>     git init --bare ~/.dotfiles\n>>>     alias dotfiles=\"GIT_DIR=~/.dotfiles GIT_WORK_TREE=~ git\"\n>>>\n>>>     dotfiles add ~/.bashrc\n>>>     dotfiles commit -a -m \"add my bashrc\"\n>>>     ...\n>>>\n>>> but git-submodule complains when trying to add submodules:\n>>>\n>>>     dotfiles submodule add http://path.to/submodule\n>>>     fatal: working tree '/home/user' already exists.\n>>>\n>>>     git --git-dir ~/.dotfiles submodule add http://path.to/submodule\n>>>     fatal: /usr/lib/git-core/git-submodule cannot be used without a\n>>> working tree.\n>>>\n>>> Signed-off-by: Daniel Graña <dangra@gmail.com>\n>>> ---\n>>\n>> I think this is in line with what we discussed earlier on list when\n>> the interaction between GIT_DIR/GIT_WORK_TREE and submodules came up\n>> the last time.  Jens?\n>\n> Yes, I think this is the only way submodules in current git can\n> be used with the GIT_DIR and GIT_WORK_TREE environment variables:\n> set them when adding or initializing the submodule and always use\n> the same settings when accessing them later. Daniel's dotfile\n> alias achieves exactly that, so his fix looks good. But I agree\n> the tests should be improved as you already pointed out.\n\nHi Jens, Junio.\n\nThanks for reviewing the patch, glad to hear this is acceptable way to\nfix my itch.\n\nI will work soon on getting the test cases improved and the patch\nsubmitted without line wrapping.\n\nthanks again,\nDaniel.\n"},{"id":"195540","messageId":"CAD77+gSa7FJuQSBRC02CqEPakbc9cNJDRWxCrYX8ZjB0wL_Syw@mail.gmail.com","threadId":"31064","inReplyTo":"7vsjcjnjvj.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Richard Hartmann","fromEmail":"richih.mailinglist@gmail.com","sentAt":"2012-07-23T18:25:21Z","receivedAt":"2012-07-23T18:25:21Z","isPatch":true,"sender":{"key":"richih.mailinglist@gmail.com","avatar":"https://avatars.githubusercontent.com/u/754723?v=4"},"body":"On Mon, Jul 23, 2012 at 7:09 AM, Junio C Hamano <gitster@pobox.com> wrote:\n\n> I think this is in line with what we discussed earlier on list when\n> the interaction between GIT_DIR/GIT_WORK_TREE and submodules came up\n> the last time.  Jens?\n\nYes, it is.\n\nI still have your email marked as TODO to get back to you as I am\nstill unsure how to solve this whole mess in a way that works with\nvcsh[1].\n\n\nRichard\n\nPS: Thanks for being so dedicated you all. I really do appreciate this\nmore than you most likely suspect.\n\n[1] vcsh\n"},{"id":"195541","messageId":"CAD77+gSRXu1hLRs0AN3z8aUUsFE-=3pmHTBaOKz7UUZ=m4bS9A@mail.gmail.com","threadId":"31064","inReplyTo":"CAD77+gSa7FJuQSBRC02CqEPakbc9cNJDRWxCrYX8ZjB0wL_Syw@mail.gmail.com","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Richard Hartmann","fromEmail":"richih.mailinglist@gmail.com","sentAt":"2012-07-23T18:27:01Z","receivedAt":"2012-07-23T18:27:01Z","isPatch":true,"sender":{"key":"richih.mailinglist@gmail.com","avatar":"https://avatars.githubusercontent.com/u/754723?v=4"},"body":"PPS: Yes, I know that I am replying in a patch thread. I will try it asap.\n"},{"id":"195562","messageId":"500DADEE.9060700@web.de","threadId":"31064","inReplyTo":"7v7gtumj88.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-07-23T20:02:54Z","receivedAt":"2012-07-23T20:02:54Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 23.07.2012 20:21, schrieb Junio C Hamano:\n> Jens Lehmann <Jens.Lehmann@web.de> writes:\n> \n>> Am 23.07.2012 07:09, schrieb Junio C Hamano:\n>>> Daniel Graña <dangra@gmail.com> writes:\n>>>\n>>>> A common way to track dotfiles with git is using GIT_DIR and\n>>>> GIT_WORK_TREE to move repository out of ~/.git with something like:\n>>>>\n>>>>     git init --bare ~/.dotfiles\n>>>>     alias dotfiles=\"GIT_DIR=~/.dotfiles GIT_WORK_TREE=~ git\"\n>>>>\n>>>>     dotfiles add ~/.bashrc\n>>>>     dotfiles commit -a -m \"add my bashrc\"\n>>>>     ...\n>>>>\n>>>> but git-submodule complains when trying to add submodules:\n>>>>\n>>>>     dotfiles submodule add http://path.to/submodule\n>>>>     fatal: working tree '/home/user' already exists.\n>>>>\n>>>>     git --git-dir ~/.dotfiles submodule add http://path.to/submodule\n>>>>     fatal: /usr/lib/git-core/git-submodule cannot be used without a\n>>>> working tree.\n>>>>\n>>>> Signed-off-by: Daniel Graña <dangra@gmail.com>\n>>>> ---\n>>>\n>>> I think this is in line with what we discussed earlier on list when\n>>> the interaction between GIT_DIR/GIT_WORK_TREE and submodules came up\n>>> the last time.  Jens?\n>>\n>> Yes, I think this is the only way submodules in current git can\n>> be used with the GIT_DIR and GIT_WORK_TREE environment variables:\n>> set them when adding or initializing the submodule and always use\n>> the same settings when accessing them later. Daniel's dotfile\n>> alias achieves exactly that, so his fix looks good. But I agree\n>> the tests should be improved as you already pointed out.\n> \n> Thanks for a quick review.  The \"the only way ... in current git can\n> be used\" part makes it sound as if it is a somewhat suboptimal ugly\n> workaround, but if that is what you meant, what is a more optimal\n> and less ugly way that you have in mind?\n\nI don't see it as an ugly workaround, I just don't see a way to get\nthe flexibility GIT_DIR and GIT_WORK_TREE offer for repos without\nsubmodules (e.g. put the work tree temporarily somewhere else for\ndeployment or compare the current work tree with the history in a\ndifferent git directory) without changing core git. I have no idea\nhow many people use this flexibility but when submodules are\ninvolved, you have to stick to the choices you made in the first\nplace or things will break. Right now the two relative links tie\nexactly two directories together as git dir and work tree. I suspect\ne.g. some setups using symlinks could benefit if we could get rid\nof one of them or even both.\n\nWe could get rid of the core.worktree setting by assuming that the\ndirectory a gitfile was found in is the root of the repo's work\ntree (unless configured otherwise). And we could introduce a new\ngitfile notation which gives the git dir relative to a parent repo's\ngit dir (e.g. \"parent: modules/name\" or such). But I'm not sure if\nit is worth the hassle.\n\n> If you want to move .git out of way with GIT_DIR and if you want to\n> sit somewhere different from the top of your working tree, you must\n> use GIT_WORK_TREE (or core.worktree) to tell where the top resides,\n> whether your project use submodules or not, so I do not think it is\n> an ugly workaround but is the one true way to use such a dismembered\n> layout, I would think.\n\nThat is a perfect use case and we should make it work.\n"},{"id":"195565","messageId":"7vd33mkyhj.fsf@alter.siamese.dyndns.org","threadId":"31064","inReplyTo":"500DADEE.9060700@web.de","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-23T20:34:48Z","receivedAt":"2012-07-23T20:34:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jens Lehmann <Jens.Lehmann@web.de> writes:\n\n> We could get rid of the core.worktree setting by assuming that the\n> directory a gitfile was found in is the root of the repo's work\n> tree (unless configured otherwise).\n\nNow you lost me.  If you have .git that is not a directory but is a\ngitfile, then you do not need GIT_DIR nor GIT_WORK_TREE in the first\nplace, no?\n"},{"id":"195594","messageId":"500DDB99.80103@web.de","threadId":"31064","inReplyTo":"7vd33mkyhj.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-07-23T23:17:45Z","receivedAt":"2012-07-23T23:17:45Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 23.07.2012 22:34, schrieb Junio C Hamano:\n> Jens Lehmann <Jens.Lehmann@web.de> writes:\n> \n>> We could get rid of the core.worktree setting by assuming that the\n>> directory a gitfile was found in is the root of the repo's work\n>> tree (unless configured otherwise).\n> \n> Now you lost me.  If you have .git that is not a directory but is a\n> gitfile, then you do not need GIT_DIR nor GIT_WORK_TREE in the first\n> place, no?\n\nNot inside the submodule, me thinks they only make sense in the\nsuperproject (that's why we clean the environment before working\ninside the submodule). But setting the superproject's GIT_WORK_TREE\nto something else won't work for an already initialized submodule,\nas the core.worktree setting will still point to the old work tree\nwhich was set when the submodule was initialized. One could expect\nthe submodule's work tree to be $GIT_WORK_TREE/$sm_path when\nGIT_WORK_TREE is set, but it isn't.\n"},{"id":"195596","messageId":"7veho2hwom.fsf@alter.siamese.dyndns.org","threadId":"31064","inReplyTo":"500DDB99.80103@web.de","subject":"Re: [PATCH] Solve git-submodule issues with detached work trees","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-23T23:42:01Z","receivedAt":"2012-07-23T23:42:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jens Lehmann <Jens.Lehmann@web.de> writes:\n\n> Not inside the submodule, me thinks they only make sense in the\n> superproject (that's why we clean the environment before working\n> inside the submodule).\n\nYes, that is fundamental and the only sane behaviour that comes from\nwhat submodules are.  They are free-standing projects.  Not clearing\nthese environments when Git recurses into submodule was simply a bug\n(the original bug was that we added recursion without thinking these\nthings through).\n\nHence...\n\n> But setting the superproject's GIT_WORK_TREE\n> to something else won't work for an already initialized submodule,\n\n... if you point the _root_ of the toplevel superproject with\nGIT_WORK_TREE (and the repository of the superproject with GIT_DIR),\nand chdir into one of its submodule's working tree, we shouldn't say\n$GIT_WORK_TREE/$smpath is the submodule world.  That will make it\nimpossible to work only on submodules by setting GIT_WORK_TREE to\npoint at its root level (and the submodule repository with GIT_DIR).\n"}]}