Merge remote-tracking branch 'cholin/repo_state'

This commit is contained in:
J. David Ibáñez
2012-11-16 16:55:34 +01:00
4 changed files with 102 additions and 0 deletions

View File

@@ -186,6 +186,68 @@ Repository_head(Repository *self)
}
PyDoc_STRVAR(
Repository_head_is_detached_doc,
"A repository's HEAD is detached when it points directly to a commit\n"
"instead of a branch.\n"
);
PyObject *
Repository_head_is_detached(Repository *self)
{
if (git_repository_head_detached(self->repo) > 0)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyDoc_STRVAR(
Repository_head_is_orphaned_doc,
"An orphan branch is one named from HEAD but which doesn't exist in\n"
"the refs namespace, because it doesn't have any commit to point to.\n"
);
PyObject *
Repository_head_is_orphaned(Repository *self)
{
if (git_repository_head_orphan(self->repo) > 0)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyDoc_STRVAR(
Repository_is_empty_doc,
"Check if a repository is empty\n"
);
PyObject *
Repository_is_empty(Repository *self)
{
if (git_repository_is_empty(self->repo) > 0)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyDoc_STRVAR(
Repository_is_bare_doc,
"Check if a repository is a bare repository.\n"
);
PyObject *
Repository_is_bare(Repository *self)
{
if (git_repository_is_bare(self->repo) > 0)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
}
PyObject *
Repository_getitem(Repository *self, PyObject *value)
{
@@ -858,6 +920,14 @@ PyGetSetDef Repository_getseters[] = {
"The normalized path to the git repository.", NULL},
{"head", (getter)Repository_head, NULL,
"Current head reference of the repository.", NULL},
{"head_is_detached", (getter)Repository_head_is_detached, NULL,
Repository_head_is_detached_doc},
{"head_is_orphaned", (getter)Repository_head_is_orphaned, NULL,
Repository_head_is_orphaned_doc},
{"is_empty", (getter)Repository_is_empty, NULL,
Repository_is_empty_doc},
{"is_bare", (getter)Repository_is_bare, NULL,
Repository_is_bare_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 "

BIN
test/data/emptyrepo.tar Normal file

Binary file not shown.

View File

@@ -47,10 +47,18 @@ A_BIN_SHA = binascii.unhexlify(A_HEX_SHA.encode('ascii'))
class RepositoryTest(utils.BareRepoTestCase):
def test_is_empty(self):
self.assertFalse(self.repo.is_empty)
def test_is_bare(self):
self.assertTrue(self.repo.is_bare)
def test_head(self):
head = self.repo.head
self.assertEqual(HEAD_SHA, head.hex)
self.assertEqual(type(head), Commit)
self.assertFalse(self.repo.head_is_orphaned)
self.assertFalse(self.repo.head_is_detached)
def test_read(self):
self.assertRaises(TypeError, self.repo.read, 123)
@@ -135,6 +143,12 @@ class RepositoryTest(utils.BareRepoTestCase):
class RepositoryTest_II(utils.RepoTestCase):
def test_is_empty(self):
self.assertFalse(self.repo.is_empty)
def test_is_bare(self):
self.assertFalse(self.repo.is_bare)
def test_get_path(self):
directory = realpath(self.repo.path)
expected = realpath(join(self._temp_dir, 'testrepo', '.git'))
@@ -163,5 +177,18 @@ class DiscoverRepositoryTest(utils.NoRepoTestCase):
os.makedirs(subdir)
self.assertEqual(repo.path, discover_repository(subdir))
class EmptyRepositoryTest(utils.EmptyRepoTestCase):
def test_is_empty(self):
self.assertTrue(self.repo.is_empty)
def test_is_base(self):
self.assertFalse(self.repo.is_bare)
def test_head(self):
self.assertTrue(self.repo.head_is_orphaned)
self.assertFalse(self.repo.head_is_detached)
if __name__ == '__main__':
unittest.main()

View File

@@ -128,3 +128,8 @@ class RepoTestCase(NoRepoTestCase):
class DirtyRepoTestCase(RepoTestCase):
repo_dir = 'dirtyrepo'
class EmptyRepoTestCase(RepoTestCase):
repo_dir = 'emptyrepo'