Merge remote-tracking branch 'nhynes/br-is-co'

This commit is contained in:
J. David Ibáñez 2017-07-05 23:20:15 +02:00
commit e81f45c4c6
3 changed files with 32 additions and 0 deletions

View File

@ -81,6 +81,28 @@ Branch_is_head(Branch *self)
return Error_set(err);
}
PyDoc_STRVAR(Branch_is_checked_out__doc__,
"is_checked_out()\n"
"\n"
"True if branch is checked out by any repo connected to the current one, "
" False otherwise.");
PyObject *
Branch_is_checked_out(Branch *self)
{
int err;
CHECK_REFERENCE(self);
err = git_branch_is_checked_out(self->reference);
if (err == 1)
Py_RETURN_TRUE;
else if (err == 0)
Py_RETURN_FALSE;
else
return Error_set(err);
}
PyDoc_STRVAR(Branch_rename__doc__,
"rename(name, force=False)\n"
@ -234,6 +256,7 @@ Branch_upstream_name__get__(Branch *self)
PyMethodDef Branch_methods[] = {
METHOD(Branch, delete, METH_NOARGS),
METHOD(Branch, is_head, METH_NOARGS),
METHOD(Branch, is_checked_out, METH_NOARGS),
METHOD(Branch, rename, METH_VARARGS),
{NULL}
};

View File

@ -34,6 +34,7 @@
PyObject* Branch_delete(Branch *self, PyObject *args);
PyObject* Branch_is_head(Branch *self);
PyObject* Branch_is_checked_out(Branch *self);
PyObject* Branch_move(Branch *self, PyObject *args);
PyObject* wrap_branch(git_reference *c_reference, Repository *repo);

View File

@ -217,6 +217,14 @@ class BranchesTestCase(utils.RepoTestCase):
branch = self.repo.lookup_branch('i18n')
self.assertFalse(branch.is_head())
def test_branch_is_checked_out_returns_true_if_branch_is_checked_out(self):
branch = self.repo.lookup_branch('master')
self.assertTrue(branch.is_checked_out())
def test_branch_is_checked_out_returns_false_if_branch_is_not_checked_out(self):
branch = self.repo.lookup_branch('i18n')
self.assertFalse(branch.is_checked_out())
def test_branch_rename_succeeds(self):
original_branch = self.repo.lookup_branch('i18n')
new_branch = original_branch.rename('new-branch')