From 0d2a3a612316e34b471d92a0c21b8a79a0f956a4 Mon Sep 17 00:00:00 2001 From: Nico von Geyso Date: Thu, 1 Nov 2012 15:35:53 +0100 Subject: [PATCH] added Repository.is_detached A repository's HEAD is detached when it points directly to a commit instead of branch. You can use repo.is_detached to check this. --- src/pygit2/repository.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/pygit2/repository.c b/src/pygit2/repository.c index 8ba3704..bd346ce 100644 --- a/src/pygit2/repository.c +++ b/src/pygit2/repository.c @@ -185,6 +185,22 @@ Repository_head(Repository *self) } +PyDoc_STRVAR( + Repository_is_detached_doc, + "A repository's HEAD is detached when it points directly to a commit\n" + "instead of a branch.\n" +); + +PyObject * +Repository_is_detached(Repository *self) +{ + if(git_repository_head_detached(self->repo) > 0) + return Py_True; + + return Py_False; +} + + PyObject * Repository_getitem(Repository *self, PyObject *value) { @@ -852,6 +868,8 @@ PyGetSetDef Repository_getseters[] = { "The normalized path to the git repository.", NULL}, {"head", (getter)Repository_head, NULL, "Current head reference of the repository.", NULL}, + {"is_detached", (getter)Repository_is_detached, NULL, + Repository_is_detached_doc}, {"config", (getter)Repository_get_config, NULL, "Get the configuration file for this repository.\n\n" "If a configuration file has not been set, the default "