Sorry for the late reply.
On Tue, Nov 02, 2021 at 03:26:05PM +0100, Johannes Schindelin wrote:
Hi Federico,
On Thu, 28 Oct 2021, Federico Kircheis wrote:
today I reported what I believed to be a bug on
https://github.com/git-for-windows/git/issues/3496
and learned about GIT_DIR when working with aliases and git worktree.
It's annoying that GIT_DIR it is defined only if (as far as I've understood)
working from a worktrees or submodule, as it does not seem to be related to
those type of repositories.
To clarify: `GIT_DIR` is set when executing an alias in a worktree other
than the primary one (and probably also in submodules), but not when
executing in a primary worktree.
This is also irritating because apparently working aliases breaks when being
executed from those repositories.
To clarify: an alias that wants to switch to a different repository and
execute Git commands there works well in a primary worktree. But when you
switch to a different repository while executing an alias from a secondary
worktree, it will fail because of `GIT_DIR` having been set.
I believe it would be better if GIT_DIR it's either always set or never
(could someone enlighten me why the variable is needed in first place?).
Yes, sorry if I was not clear, your clarification are what I meant to
say.
The fact that `GIT_DIR` is not set when calling an alias in a primary
worktree suggests that the behavior in secondary worktrees is not by
design. We should therefore be able to stop setting it there.
The question is: what code is responsible for setting it only in some
circumstances but not others?
Federico, do you have any experience in debugging C code? If so, it would
be good if you could take a crack at investigating this.
Ciao,
Johannes
Yes, I have some experience, but never looked at the git codebase.
On GitHub (https://github.com/git-for-windows/git/issues/3496) there is
already an hint where those variables are set:
https://github.com/git/git/blob/v2.33.1/git.c#L354
Or do you mean if I could investigate the test cases Ævar Arnfjörð
Bjarmason mentioned?