Skip to content

Commit 40f1424

Browse files
Add Commit.is_shallow property; document stats() limitation at shallow boundary (#2167)
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>
1 parent b920dcd commit 40f1424

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ Contributors are:
5757
-Jonas Scharpf <jonas.scharpf _at_ checkmk.com>
5858
-Gordon Marx
5959
-Enji Cooper
60+
-Harshita Yadav <harshitayadav504 _at_ gmail.com>
6061

6162
Portions derived from other open source works and are clearly marked.

git/objects/commit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ def stats(self) -> Stats:
374374
"""Create a git stat from changes between this commit and its first parent
375375
or from all changes done if this is the very first commit.
376376
377+
:note:
378+
If this commit is at the boundary of a shallow clone, this will
379+
raise :exc:`~git.exc.GitCommandError`, since the parent object
380+
was never fetched and only exists as a reference on this commit.
381+
377382
:return:
378383
:class:`Stats`
379384
"""

0 commit comments

Comments
 (0)