Implement Branch.is_head.

This commit is contained in:
Daniel Rodríguez Troitiño
2013-05-17 22:50:38 +02:00
parent 79f1e54153
commit 2f08236aec
3 changed files with 32 additions and 0 deletions

View File

@@ -57,8 +57,31 @@ Branch_delete(Branch *self, PyObject *args)
}
PyDoc_STRVAR(Branch_is_head__doc__,
"is_head()\n"
"\n"
"True if HEAD points at the branch, False otherwise.");
PyObject *
Branch_is_head(Branch *self)
{
int err;
CHECK_REFERENCE(self);
err = git_branch_is_head(self->reference);
if (err == 1)
Py_RETURN_TRUE;
else if (err == 0)
Py_RETURN_FALSE;
else
return Error_set(err);
}
PyMethodDef Branch_methods[] = {
METHOD(Branch, delete, METH_NOARGS),
METHOD(Branch, is_head, METH_NOARGS),
{NULL}
};

View File

@@ -33,6 +33,7 @@
#include <git2.h>
PyObject* Branch_delete(Branch *self, PyObject *args);
PyObject* Branch_is_head(Branch *self);
PyObject* wrap_branch(git_reference *c_reference, Repository *repo);

View File

@@ -79,6 +79,14 @@ class BranchesTestCase(utils.RepoTestCase):
self.assertRaises(pygit2.GitError, lambda: branch.delete())
def test_branch_is_head_returns_true_if_branch_is_head(self):
branch = self.repo.lookup_branch('master')
self.assertTrue(branch.is_head())
def test_branch_is_head_returns_false_if_branch_is_not_head(self):
branch = self.repo.lookup_branch('i18n')
self.assertFalse(branch.is_head())
class BranchesEmptyRepoTestCase(utils.EmptyRepoTestCase):
def setUp(self):