threads / discuss / 61114

Sparse worktree always contains root files

Subject: Sparse worktree always contains root files

## tl;dr

2 messages between Mar 13, 2024 and Mar 13, 2024.

replies: 1people: 2as markdown or json

Jeppe Øland· Mar 13, 2024, 18:16 UTC · lore
Hi there,

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.

This also happens with traditional (non-worktree) partial clones. (I did both shallow, blob-less and tree-less, and all of them behave the same way)

Regards, -Jeppe

Junio C Hamano· Mar 13, 2024, 18:34 UTC · re: Jeppe Øland · lore

Re: Sparse worktree always contains root files

Jeppe Øland <joland@gmail.com> writes:
Show 10 quoted lines
> 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.

← back to recent threads