Subject: Re: '.git file' alternative, native (cross-platform) workdir support.

From: Junio C Hamano <[email-masked]>
Date: Fri, 29 Feb 2008 12:02:42 -0800

Johannes Schindelin <[email-masked]> writes:

> On Fri, 29 Feb 2008, Marius Storm-Olsen wrote:
>
>> I just caught a glimpse of the '.git file' efforts, as a file for 
>> redirection to a real repository.
>> 
>> As far as I can tell, the reason for adding the support is to in the end 
>> provide a cross-platform way of supporting workdirs. (If this is not the 
>> [main] point, please point me to the thread describing the real reason, 
>> I couldn't find it.)
>
> This is the main reason, yes.

I do not think so.  For repository and work tree separation, we already
have core.worktree.  Multiple work trees attached to a single repository
is what contrib/workdir/ does, and it could probably be extended, but that
one needs more than "redirect .git elsewhere".

The primary reason we may want to do the ".git file" thing is to sanely
support switching between branches (or checking out a different revision,
which amounts to the same thing) when one has a submodule and the other
one either does not have that submodule anywhere or have it in a different
location in its tree.

Suppose the HEAD one binds a submodule "gitk" at gitk-git.  Then suppose
we want to switch to an old branch that did not have that submodule bound
yet.  Or the branch we are switching to has the submodule at modules/gitk.
What happens?

Currently, when we are on HEAD, we create a directory at gitk-git and make
gitk-git/.git directory its controlling repository (i.e. GIT_DIR).
Switching to a branch that did not have the submodule bound will need to
rmdir gitk-git (this needs to happen no matter what) but as a side effect
we will lose gitk-git/.git repository.  Switching back to where we were
would require reloading that repository from somewhere else, but if you
are "the upstream", that somewhere else may not even exist.

One way to solve this would be to add .git/submodules/paulus.git
repository inside the controlling reopsitory of the toplevel project, and
point that with the ".git file" installed at gitk-git/.git, when we are on
HEAD.  We can lose gitk-git directory and everything below it when
switching away from the revision, but when we come back, we can recreate
gitk-git directory, point gitk-git/.git back to .git/submodules/paulus.git
kept in the toplevel repository, and check the appropriate commit out there.

After switching to an old revision that did not have the submodule,
further switching to a branch that has the submodule at modules/gitk would
be the same deal.  Instead of creating gitk-git directory and installing
the ".git file" there (which is what we did when we came back to the
original HEAD), create modules/gitk and install the ".git file" there, to
point at the same .git/submodules/paulus.git/.

We should be able to do this today without ".git file" using symlinks.
It's just a Porcelain hackery, so I'll leave it to interested parties as
an exercise.