Subject: Re: Sparse worktree always contains root files

From: Junio C Hamano <[email-masked]>
Date: Wed, 13 Mar 2024 11:34:26 -0700

Jeppe Øland <[email-masked]> writes:

> I'm trying to use sparse checkouts in a large project, and one oddity
> (bug?) came up.
>
> If I do a normal full clone of a repository, then do:
>     git worktree add ../sparse --no-checkout
>     cd ../sparse
>     git sparse-checkout set somepath
>     git checkout
> Now indeed it is a sparse worktree, but the files from the root
> directory are also there.

I think this is working as intended.

Without knowing about the non-tree entries' object names, you cannot
create your next commit on top, as you need to be able to compute
the tree object's contents.  You'd update some files in "somepath",
and that directory being populated you can compute the object name
of the tree that represents the state of "somepath" after your
update.  But that object name must be mixed with other things in the
same directory as "somepath" (i.e. in the root tree), so they must
be known.