Implement Branch.is_head.
This commit is contained in:
23
src/branch.c
23
src/branch.c
@@ -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[] = {
|
PyMethodDef Branch_methods[] = {
|
||||||
METHOD(Branch, delete, METH_NOARGS),
|
METHOD(Branch, delete, METH_NOARGS),
|
||||||
|
METHOD(Branch, is_head, METH_NOARGS),
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
PyObject* Branch_delete(Branch *self, PyObject *args);
|
PyObject* Branch_delete(Branch *self, PyObject *args);
|
||||||
|
PyObject* Branch_is_head(Branch *self);
|
||||||
|
|
||||||
PyObject* wrap_branch(git_reference *c_reference, Repository *repo);
|
PyObject* wrap_branch(git_reference *c_reference, Repository *repo);
|
||||||
|
|
||||||
|
@@ -79,6 +79,14 @@ class BranchesTestCase(utils.RepoTestCase):
|
|||||||
|
|
||||||
self.assertRaises(pygit2.GitError, lambda: branch.delete())
|
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):
|
class BranchesEmptyRepoTestCase(utils.EmptyRepoTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Reference in New Issue
Block a user