Add Commit.is_shallow property; document stats() limitation at shallow boundary#2167
Open
harshitayadavv wants to merge 2 commits into
Open
Add Commit.is_shallow property; document stats() limitation at shallow boundary#2167harshitayadavv wants to merge 2 commits into
harshitayadavv wants to merge 2 commits into
Conversation
…llow boundary Accessing .stats on a commit at the boundary of a shallow clone raises GitCommandError because the commit's parent SHA was never fetched. This adds an is_shallow property to detect this case ahead of time by checking the repository's shallow file, and documents the limitation on stats(). Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Accessing
.statson a commit at the boundary of a shallow clone raisesgit.exc.GitCommandError: fatal: bad object <sha>. This happens becausethe commit object itself still references its parent's SHA, but that
parent was never fetched — it's beyond the shallow depth. There's currently
no way to detect this ahead of time without hitting the crash.
Reproduction
Fix
Adds a
Commit.is_shallowproperty that checks whether the commit's hexshaappears in the repository's
shallowfile -- a cheap, local check with nogit subprocess call. Also documents this limitation in the
statsdocstring, pointing to
is_shallow.Includes a test (
test_is_shallow) that reproduces the failure via a reallocal shallow clone (using
no_local=True, since Git ignores--depthforlocal-optimized clones) and confirms both that the boundary commit reports
is_shallow == Trueand that.statsraises as expected on it.Ran the full test suite locally (Windows, Python 3.11): 660 passed, 9
unrelated pre-existing failures (Windows symlink privilege requirements,
a missing-remote assumption in one tutorial test, and PATH resolution in
shell-impostor tests) -- none touching commit.py or stats.
AI disclosure
Per CONTRIBUTING.md: I used Claude to help design, implement, and test
this change. I reviewed, ran, and verified every step myself, including
reproducing the underlying bug firsthand before writing the fix.