Uh oh!
There was an error while loading. Please reload this page.
Add Commit.is_shallow property; document stats() limitation at shallow boundary - #2167
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>
Byron
left a comment
There was a problem hiding this comment.
Thanks for giving this a shot.
Can we reduce this to just the documentation change for a quick merge? Otherwise, the .is_shallow() should rather be on Repo to support testing multiple commits at the same time. I wouldn't want to encourage per-commit calls given they are IO-heavy then. Alternatively, offer a way to get a set of hashes that are the shallow boundary so users can do their is-contained checks themselves.
Per @Byron's feedback: dropping the is_shallow property, since a per-commit property re-reads the shallow file on every call, which is IO-heavy when checking many commits. Keeping just the stats() docstring note about the limitation for a quick merge. Happy to follow up with a Repo-level implementation (e.g. returning the set of shallow-boundary hashes) as a separate PR if useful.
harshitayadavv
commented
Jul 12, 2026
@Byron Done, reduced to just the docstring note on stats(). Happy to follow up separately with a Repo-level version (e.g. a method returning the set of shallow-boundary hashes) if that'd be useful. |
Uh oh!
There was an error while loading. Please reload this page.
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.