Skip to content

repository: read and write the shallow file in commondir - #7488

Open
Grinv wants to merge 1 commit into
libgit2:mainfrom
Grinv:shallow-commondir
Open

Grinv wants to merge 1 commit into
libgit2:mainfrom
Grinv:shallow-commondir

Conversation

@Grinv

@Grinv Grinv commented Nov 20, 2026

Copy link
Copy Markdown

git keeps shallow in the common directory, but libgit2 read and wrote it in the worktree's gitdir. In a linked worktree of a shallow clone, a revwalk therefore fails with "object not found" at the shallow boundary, although git_repository_is_shallow already reports the worktree as shallow (#7322).

This adds GIT_REPOSITORY_ITEM_SHALLOW (common directory, gitdir as fallback, like config) and uses it in load_grafts, git_repository__shallow_roots_write and git_repository_is_shallow. The public enum grows by one value, as it did for GIT_REPOSITORY_ITEM_WORKTREE_CONFIG; a private path helper would also work if you'd rather not touch the API.

In-memory repositories have no common directory, so git_repository_is_shallow used to check shallow relative to the current directory; it now returns 0.

The new tests in grafts/shallow.c fail without the change. repo::shallow::worktree_of_shallow_parent wrote x into the parent's shallow, which the worktree now parses, so it writes a commit id instead. The full suite passes on Linux.

Found while looking into #7487.

Prepared with Claude Code; I reviewed the changes.

git keeps the `shallow` file in the common directory, so all
worktrees of a shallow repository share it. libgit2 read and wrote it
in the worktree's gitdir instead, so a history walk in a linked
worktree of a shallow clone failed with "object not found" at the
shallow boundary. git_repository_is_shallow already looks in the
common directory since libgit2#7322.

Add GIT_REPOSITORY_ITEM_SHALLOW and use it when loading grafts,
writing shallow roots and in git_repository_is_shallow. In-memory
repositories no longer look for `shallow` in the current directory.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant