{"thread":{"id":"52347","subject":"Bug? clone ignores --git-dir","startedAt":"2019-11-26T18:13:51Z","lastAt":"2019-11-27T20:19:07Z","messageCount":4,"participants":["Jack Bates","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"387095","messageId":"7d28416e-c927-4cd3-bac2-d8bfd02ce949@nottheoilrig.com","threadId":"52347","inReplyTo":null,"subject":"Bug? clone ignores --git-dir","fromName":"Jack Bates","fromEmail":"bk874k@nottheoilrig.com","sentAt":"2019-11-26T18:07:27Z","receivedAt":"2019-11-26T18:13:51Z","isPatch":false,"sender":{"key":"bk874k@nottheoilrig.com","avatar":null},"body":"If you `git rebase --exec 'gulp runtests-parallel --runners user'` this \nproject, the tests perform Git operations on various subprojects [1], \nbut because Git exports `GIT_DIR` and `GIT_WORK_TREE`, they end up \noperating on the parent project instead.\n\nAdding `--git-dir` and `--work-tree` overrides `GIT_DIR` and \n`GIT_WORK_TREE` [2], forcing the tests to operate on the correct \nrepositories, however `clone` ignores `--git-dir`:\n\n> git init repository\n> git --git-dir git-dir clone repository directory\nI'd expect Git to create a directory `git-dir` and put the index, etc. \nthere, but instead it creates `directory/.git`, as usual. I'm not sure \nif this is a bug or the expected behavior?\n\n[1] \nhttps://github.com/microsoft/TypeScript/blob/master/src/testRunner/externalCompileRunner.ts#L58\n[2] https://github.com/microsoft/TypeScript/pull/35362\n"},{"id":"387143","messageId":"20191127115124.GE22221@sigill.intra.peff.net","threadId":"52347","inReplyTo":"7d28416e-c927-4cd3-bac2-d8bfd02ce949@nottheoilrig.com","subject":"Re: Bug? clone ignores --git-dir","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-11-27T11:51:24Z","receivedAt":"2019-11-27T11:51:26Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Nov 26, 2019 at 11:07:27AM -0700, Jack Bates wrote:\n\n> If you `git rebase --exec 'gulp runtests-parallel --runners user'` this\n> project, the tests perform Git operations on various subprojects [1], but\n> because Git exports `GIT_DIR` and `GIT_WORK_TREE`, they end up operating on\n> the parent project instead.\n> \n> Adding `--git-dir` and `--work-tree` overrides `GIT_DIR` and `GIT_WORK_TREE`\n> [2], forcing the tests to operate on the correct repositories, however\n> `clone` ignores `--git-dir`:\n> \n> > git init repository\n> > git --git-dir git-dir clone repository directory\n> I'd expect Git to create a directory `git-dir` and put the index, etc.\n> there, but instead it creates `directory/.git`, as usual. I'm not sure if\n> this is a bug or the expected behavior?\n\nThis is the expected behavior. \"clone\" and \"init\" are special in that\nthey are creating _new_ repositories, so they explicitly ignore the\nany notion of the current repository.\n\nI'm not quite sure what you're trying to do. I'd think:\n\n  git clone --bare repository git-dir\n\nwould do what you want, but then I'm not sure why you're specifying\n\"directory\" in the first place, or what you expect to happen. Are you\nlooking for clone's --separate-git-dir option, perhaps?\n\n-Peff\n"},{"id":"387148","messageId":"xmqqh82pv6qi.fsf@gitster-ct.c.googlers.com","threadId":"52347","inReplyTo":"7d28416e-c927-4cd3-bac2-d8bfd02ce949@nottheoilrig.com","subject":"Re: Bug? clone ignores --git-dir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-11-27T12:33:41Z","receivedAt":"2019-11-27T12:33:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jack Bates <bk874k@nottheoilrig.com> writes:\n\n> ... repositories, however `clone` ignores `--git-dir`:\n\nAn intentional design decision (and it may be an unfortunate one by\nnow [*1*]) was to have the GIT_DIR (hence --git-dir) talk about the\n*source side* of the clone, not the destination, e.g.\n\n\tcd /home/me/working/tree\n\texport GIT_DIR=/home/me/repo/sitory\n\texport GIT_WORK_TREE=$(pwd)\n\n\t# the above told Git that /home/me/working/tree has a\n\t# checkout but its repository body is not anywhere in its\n\t# subdirectory -- it is /home/me/repo/sitory.\n\n\t# now we clone the repository we are currently working on\n\t# without GIT_DIR applying to the source side, it won't\n\t# work.\n\tgit clone . /else/where\n\nAnd we cannot allow /home/me/repo/sitory (i.e. GIT_DIR for the\nsource repository) become the GIT_DIR for the resulting /else/where\nrepository (you'd be cloning to yourself).\n\n\n[Footnote]\n\n*1* with use of \"git worktree\" gaining traction, perhaps the need to\n    create local clone out of the shared/same GIT_DIR may have\n    diminished.\n\n"},{"id":"387244","messageId":"91fa0f24-fd11-a0ff-c258-c0f480910ade@nottheoilrig.com","threadId":"52347","inReplyTo":"xmqqh82pv6qi.fsf@gitster-ct.c.googlers.com","subject":"Re: Bug? clone ignores --git-dir","fromName":"Jack Bates","fromEmail":"bk874k@nottheoilrig.com","sentAt":"2019-11-27T20:19:05Z","receivedAt":"2019-11-27T20:19:07Z","isPatch":false,"sender":{"key":"bk874k@nottheoilrig.com","avatar":null},"body":"On 2019-11-27 5:33 a.m., Junio C Hamano wrote:\n> An intentional design decision (and it may be an unfortunate one by\n> now [*1*]) was to have the GIT_DIR (hence --git-dir) talk about the\n> *source side* of the clone, not the destination, e.g.\n\nAh ha, the following does what I want, regardless of \n`GIT_DIR`/`GIT_WORK_TREE`:\n\n> git init repository\n> GIT_DIR=bogus GIT_WORK_TREE=bogus git --work-tree directory clone repository directory/.git\n\nThank you!\n"}]}