Skip to content

Fails in sparse-index repos with unsupported sdir index extension #214

@DavidTeju

Description

@DavidTeju

Summary

git-absorb fails in Git repositories that use cone-mode sparse checkout with sparse-index enabled. The failure comes from libgit2/git2-rs being unable to read the Git index when it contains the required sparse-directory sdir extension.

Observed error:

absorb failed, err: unsupported mandatory extension: 'sdir'; class=Index (10)

I filed the underlying libgit2 feature/support issue here:

Repro outline

Create a repo with enough directories to produce sparse-directory entries, enable sparse-index, stage a change inside the sparse cone, then run git-absorb:

git init sdir-repro
cd sdir-repro
git config user.name 'Sparse Index Repro'
git config user.email 'sparse-index-repro@example.invalid'

printf 'initial\n' > initial.txt
git add initial.txt
git commit -m 'initial'

for i in $(seq 1 200); do
  mkdir -p "src/dir$i"
  printf 'base %s\n' "$i" > "src/dir$i/file$i.txt"
done

git add src
git commit -m 'seed sparse base tree'

git checkout -b feature/sparse-index
printf 'base 1\nfeature line\n' > src/dir1/file1.txt
git commit -am 'feature dir1'

git sparse-checkout init --cone --sparse-index
git sparse-checkout set src/dir1

printf 'base 1\nfeature line\nreview fix\n' > src/dir1/file1.txt
git add src/dir1/file1.txt

git absorb --base HEAD~1 --dry-run

Expected: git-absorb reads the index and reports/creates a fixup.

Actual:

absorb failed, err: unsupported mandatory extension: 'sdir'; class=Index (10)

Workaround

This works around the failure by temporarily expanding the index:

git sparse-checkout reapply --no-sparse-index
git absorb --base HEAD~1 --dry-run
git sparse-checkout reapply --sparse-index

That preserves sparse-checkout patterns, but it can be expensive in very large monorepos because it rewrites the index as a full index.

Notes

This may not be directly fixable in git-absorb until libgit2 supports sdir, but it may be worth tracking here because git-absorb is the user-facing command that reports the failure. A possible mitigation would be documenting the workaround or detecting this specific error and printing targeted guidance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamBlocked on upstream libgit2/git2rs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions