Skip to content

Commit 7371d70

Browse files
committed
repository: add .is_shallow to detect shallow clones
1 parent 12f293b commit 7371d70

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/repository.c

+14
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,19 @@ Repository_is_bare__get__(Repository *self)
264264
}
265265

266266

267+
PyDoc_STRVAR(Repository_is_shallow__doc__,
268+
"Check if a repository is a shallow repository.");
269+
270+
PyObject *
271+
Repository_is_shallow__get__(Repository *self)
272+
{
273+
if (git_repository_is_shallow(self->repo) > 0)
274+
Py_RETURN_TRUE;
275+
276+
Py_RETURN_FALSE;
277+
}
278+
279+
267280
PyDoc_STRVAR(Repository_git_object_lookup_prefix__doc__,
268281
"git_object_lookup_prefix(oid) -> Object\n"
269282
"\n"
@@ -2130,6 +2143,7 @@ PyGetSetDef Repository_getseters[] = {
21302143
GETTER(Repository, head_is_unborn),
21312144
GETTER(Repository, is_empty),
21322145
GETTER(Repository, is_bare),
2146+
GETTER(Repository, is_shallow),
21332147
GETSET(Repository, workdir),
21342148
GETTER(Repository, default_signature),
21352149
GETTER(Repository, odb),

test/test_repository.py

+9
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,12 @@ def test_open_extended(tmp_path):
633633
assert repo.is_bare
634634
assert repo.path == orig_repo.path
635635
assert not repo.workdir
636+
637+
def test_is_shallow(testrepo):
638+
assert not testrepo.is_shallow
639+
640+
# create a dummy shallow file
641+
with open(os.path.join(testrepo.path, 'shallow'), 'wt') as f:
642+
f.write('abcdef0123456789abcdef0123456789abcdef00\n')
643+
644+
assert testrepo.is_shallow

0 commit comments

Comments
 (0)