{"thread":{"id":"35693","subject":"GIT_WORK_TREE and GIT_DIR with git clone","startedAt":"2014-01-20T15:59:16Z","lastAt":"2014-01-21T21:37:16Z","messageCount":3,"participants":["Cosmin Apreutesei","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"233399","messageId":"CAKJdRamFDDWRZDHBCe7GrXg0OWhLfBPq_ofsvowaW9d8VOGTMA@mail.gmail.com","threadId":"35693","inReplyTo":null,"subject":"GIT_WORK_TREE and GIT_DIR with git clone","fromName":"Cosmin Apreutesei","fromEmail":"cosmin.apreutesei@gmail.com","sentAt":"2014-01-20T15:59:16Z","receivedAt":"2014-01-20T15:59:16Z","isPatch":false,"sender":{"key":"cosmin.apreutesei@gmail.com","avatar":"https://gravatar.com/avatar/f66abe8cb4ae1faa0af3562b5f140e4add185ceef77ca5505d5f145cb8b4a5b3?d=mp&s=160"},"body":"Hi,\n\nI would like to have git clone respect GIT_DIR (and --git-dir) so I\ncan clone multiple repos into the same working directory (I know there\nwas another request for this[1]).\n\nThe pattern here is big projects that are modularized into multiple\ngit repositories, but supposed to be overlaid over a common directory\nstructure.\n\nI would like to be able to tell my users that they can simply do:\n\ngit clone --git-dir=_/git/module1/.git module1-url\ngit clone --git-dir=_/git/module2/.git module2-url\n\nwhich will overlay the files from both modules into the current\ndirectory, which from git's perspective is the work-tree for both\nmodules.\n\n\n[1] http://article.gmane.org/gmane.comp.version-control.git/170073/match=git_work_tree+git_dir+git+clone\n"},{"id":"233459","messageId":"xmqq4n4xulrm.fsf@gitster.dls.corp.google.com","threadId":"35693","inReplyTo":"CAKJdRamFDDWRZDHBCe7GrXg0OWhLfBPq_ofsvowaW9d8VOGTMA@mail.gmail.com","subject":"Re: GIT_WORK_TREE and GIT_DIR with git clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-01-21T20:23:41Z","receivedAt":"2014-01-21T20:23:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Cosmin Apreutesei <cosmin.apreutesei@gmail.com> writes:\n\n> I would like to be able to tell my users that they can simply do:\n>\n> git clone --git-dir=_/git/module1/.git module1-url\n> git clone --git-dir=_/git/module2/.git module2-url\n>\n> which will overlay the files from both modules into the current\n> directory, which from git's perspective is the work-tree for both\n> modules.\n\nWould there be a sensible semantics in the resulting working tree?\nWhich repository would a new file in such a combined working tree\nbelong to?\n"},{"id":"233464","messageId":"CAKJdRakBWR7ofvcc8uhQ09QwiAJs7uvRNwP3WyuF4ve7FWONgw@mail.gmail.com","threadId":"35693","inReplyTo":"xmqq4n4xulrm.fsf@gitster.dls.corp.google.com","subject":"Re: GIT_WORK_TREE and GIT_DIR with git clone","fromName":"Cosmin Apreutesei","fromEmail":"cosmin.apreutesei@gmail.com","sentAt":"2014-01-21T21:37:16Z","receivedAt":"2014-01-21T21:37:16Z","isPatch":false,"sender":{"key":"cosmin.apreutesei@gmail.com","avatar":"https://gravatar.com/avatar/f66abe8cb4ae1faa0af3562b5f140e4add185ceef77ca5505d5f145cb8b4a5b3?d=mp&s=160"},"body":"Hi, thanks for answering.\n\n>> I would like to be able to tell my users that they can simply do:\n>>\n>> git clone --git-dir=_/git/module1/.git module1-url\n>> git clone --git-dir=_/git/module2/.git module2-url\n>>\n>> which will overlay the files from both modules into the current\n>> directory, which from git's perspective is the work-tree for both\n>> modules.\n>\n> Would there be a sensible semantics in the resulting working tree?\n> Which repository would a new file in such a combined working tree\n> belong to?\n\nThe developer would have to decide by way of `git add`.\n\nIgnoring other repos' files would be done by way of local config\noption `excludesfile` (.gitignore is out).\n\nTo make it easier to work with git this way, a script that creates a\nsubshell in the context of a repo can be done with something like\n`PS1=\"[$1 $PS1]\" GIT_DIR=_git/$1/.git bash -i\" -- git would then work\nas usual in that subshell for that specific repo, never leaving the\nworking tree.\n\n\nI successfully employed the above scheme with luapower[1] packages,\nwhich are all different and mostly unrelated libraries, but which need\nto be overlaid over a common directory structure. And that's just an\nexample. I can think of many projects that are modularized and yet the\nmodules need to place many files in many places to make a working\nsystem (web frameworks, the linux filesystem, etc.)\n\nCurrently, to clone a repo one has to do:\n\nexport GIT_DIR=_git/submodule/.git\ngit init\ngit config --local core.worktree ../../..\ngit remote add origin ssh://git@github.com/luapower/submodule.git\ngit fetch\ngit branch --track master origin/master\ngit checkout\n\nThat's 6 commands for what could be:\n\n    git clone --git-dir=_git/submodule/.git\nssh://git@github.com/luapower/submodule.git\n\nOr even better:\n\n    git clone --git-dirs=_git ssh://git@github.com/luapower/submodule.git\n\n[1] http://luapower.com\n"}]}