{"thread":{"id":"26872","subject":"GIT_WORK_TREE and GIT_DIR with git clone","startedAt":"2011-03-26T12:58:18Z","lastAt":"2011-03-26T23:37:28Z","messageCount":3,"participants":["Kacper Kornet","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"164360","messageId":"20110326125818.GA2621@camk.edu.pl","threadId":"26872","inReplyTo":null,"subject":"GIT_WORK_TREE and GIT_DIR with git clone","fromName":"Kacper Kornet","fromEmail":"kornet@camk.edu.pl","sentAt":"2011-03-26T12:58:18Z","receivedAt":"2011-03-26T12:58:18Z","isPatch":false,"sender":{"key":"kornet@camk.edu.pl","avatar":null},"body":"Is there a reason why git clone does not respect GIT_DIR\nvariable. I have found it confusing that:\n\nGIT_WORK_TREE=repo GIT_DIR=repo/.git git clone <path>/repo.git\n\nis not equivalent to\n\ngit clone <path>/repo.git\n\n-- \n  Kacper\n"},{"id":"164380","messageId":"7vtyep3c1h.fsf@alter.siamese.dyndns.org","threadId":"26872","inReplyTo":"20110326125818.GA2621@camk.edu.pl","subject":"Re: GIT_WORK_TREE and GIT_DIR with git clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-26T19:40:58Z","receivedAt":"2011-03-26T19:40:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kacper Kornet <kornet@camk.edu.pl> writes:\n\n> Is there a reason why git clone does not respect GIT_DIR\n> variable.\n\nAre you sure it does \"not respect GIT_DIR\"?  When you are running clone\nlocally, like that:\n\n> GIT_WORK_TREE=repo GIT_DIR=repo/.git git clone <path>/repo.git\n\nyou have _two_ repositories that the command operates on on your system,\nthe one that you are cloning _from_, and the new one that you are\ncreating.\n\nWhich repository does your GIT_DIR talk about?\n"},{"id":"164382","messageId":"20110326233728.GA9445@camk.edu.pl","threadId":"26872","inReplyTo":"7vtyep3c1h.fsf@alter.siamese.dyndns.org","subject":"Re: GIT_WORK_TREE and GIT_DIR with git clone","fromName":"Kacper Kornet","fromEmail":"kornet@camk.edu.pl","sentAt":"2011-03-26T23:37:28Z","receivedAt":"2011-03-26T23:37:28Z","isPatch":false,"sender":{"key":"kornet@camk.edu.pl","avatar":null},"body":"On Sat, Mar 26, 2011 at 12:40:58PM -0700, Junio C Hamano wrote:\n> Kacper Kornet <kornet@camk.edu.pl> writes:\n\n> > Is there a reason why git clone does not respect GIT_DIR\n> > variable.\n\n> Are you sure it does \"not respect GIT_DIR\"?  When you are running clone\n> locally, like that:\n\n> > GIT_WORK_TREE=repo GIT_DIR=repo/.git git clone <path>/repo.git\n\n> you have _two_ repositories that the command operates on on your system,\n> the one that you are cloning _from_, and the new one that you are\n> creating.\n\n> Which repository does your GIT_DIR talk about?\n\nI would expect that GIT_DIR always talks the new one. For example after:\n\nGIT_WORK_TREE=dir GIT_DIR=dir/.git git clone git://git.kernel.org/pub/scm/gitk/gitk\n\nI would expect to have repo in dir/.git. What happens is that in dir\nthere is a working tree and in local directory gitk there is a bare\nrepo. The following patch should fix the issue:\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex c6e10bb..082ee53 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -442,11 +442,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\t\tdie(\"working tree '%s' already exists.\", work_tree);\n \t}\n \n-\tif (option_bare || work_tree)\n-\t\tgit_dir = xstrdup(dir);\n-\telse {\n+\tgit_dir = getenv(\"GIT_DIR\");\n+\tif (option_bare || work_tree) {\n+\t\tif (!git_dir)\n+\t\t\tgit_dir = xstrdup(dir);\n+\t} else {\n \t\twork_tree = dir;\n-\t\tgit_dir = xstrdup(mkpath(\"%s/.git\", dir));\n+\t\tif (!git_dir)\n+\t\t\tgit_dir = xstrdup(mkpath(\"%s/.git\", dir));\n \t}\n \n \tif (!option_bare) {\n\n\n\n\n\n-- \n  Kacper \n"}]}