threads / bug / 52347

Bug? clone ignores --git-dir

Subject: Bug? clone ignores --git-dir

## tl;dr

4 messages between Nov 26, 2019 and Nov 27, 2019.

replies: 3people: 3as markdown or json

Jack Bates· Nov 26, 2019, 18:07 UTC · lore

If you `git rebase --exec 'gulp runtests-parallel --runners user'` this project, the tests perform Git operations on various subprojects [1], but because Git exports `GIT_DIR` and `GIT_WORK_TREE`, they end up operating on the parent project instead.

Adding `--git-dir` and `--work-tree` overrides `GIT_DIR` and `GIT_WORK_TREE` [2], forcing the tests to operate on the correct repositories, however `clone` ignores `--git-dir`:

> git init repository
> git --git-dir git-dir clone repository directory

I'd expect Git to create a directory `git-dir` and put the index, etc. there, but instead it creates `directory/.git`, as usual. I'm not sure if this is a bug or the expected behavior?

[1] https://github.com/microsoft/TypeScript/blob/master/src/testRunner/externalCompileRunner.ts#L58 [2] https://github.com/microsoft/TypeScript/pull/35362

Jeff King· Nov 27, 2019, 11:51 UTC · re: Jack Bates · lore

Re: Bug? clone ignores --git-dir

On Tue, Nov 26, 2019 at 11:07:27AM -0700, Jack Bates wrote:
Show 14 quoted lines
> If you `git rebase --exec 'gulp runtests-parallel --runners user'` this
> project, the tests perform Git operations on various subprojects [1], but
> because Git exports `GIT_DIR` and `GIT_WORK_TREE`, they end up operating on
> the parent project instead.
> 
> Adding `--git-dir` and `--work-tree` overrides `GIT_DIR` and `GIT_WORK_TREE`
> [2], forcing the tests to operate on the correct repositories, however
> `clone` ignores `--git-dir`:
> 
> > git init repository
> > git --git-dir git-dir clone repository directory
> I'd expect Git to create a directory `git-dir` and put the index, etc.
> there, but instead it creates `directory/.git`, as usual. I'm not sure if
> this is a bug or the expected behavior?

This is the expected behavior. "clone" and "init" are special in that they are creating _new_ repositories, so they explicitly ignore the any notion of the current repository.

I'm not quite sure what you're trying to do. I'd think:
  git clone --bare repository git-dir

would do what you want, but then I'm not sure why you're specifying "directory" in the first place, or what you expect to happen. Are you looking for clone's --separate-git-dir option, perhaps?

-Peff
Junio C Hamano· Nov 27, 2019, 12:33 UTC · re: Jack Bates · lore

Re: Bug? clone ignores --git-dir

Jack Bates <bk874k@nottheoilrig.com> writes:
> ... repositories, however `clone` ignores `--git-dir`:

An intentional design decision (and it may be an unfortunate one by now [*1*]) was to have the GIT_DIR (hence --git-dir) talk about the *source side* of the clone, not the destination, e.g.

	cd /home/me/working/tree
	export GIT_DIR=/home/me/repo/sitory
	export GIT_WORK_TREE=$(pwd)
	# the above told Git that /home/me/working/tree has a
	# checkout but its repository body is not anywhere in its
	# subdirectory -- it is /home/me/repo/sitory.
	# now we clone the repository we are currently working on
	# without GIT_DIR applying to the source side, it won't
	# work.
	git clone . /else/where

And we cannot allow /home/me/repo/sitory (i.e. GIT_DIR for the source repository) become the GIT_DIR for the resulting /else/where repository (you'd be cloning to yourself).

[Footnote]
*1* with use of "git worktree" gaining traction, perhaps the need to
    create local clone out of the shared/same GIT_DIR may have
    diminished.
Jack Bates· Nov 27, 2019, 20:19 UTC · re: Junio C Hamano · lore

Re: Bug? clone ignores --git-dir

On 2019-11-27 5:33 a.m., Junio C Hamano wrote:
> An intentional design decision (and it may be an unfortunate one by
> now [*1*]) was to have the GIT_DIR (hence --git-dir) talk about the
> *source side* of the clone, not the destination, e.g.

Ah ha, the following does what I want, regardless of `GIT_DIR`/`GIT_WORK_TREE`:

> git init repository
> GIT_DIR=bogus GIT_WORK_TREE=bogus git --work-tree directory clone repository directory/.git
Thank you!

← back to recent threads