Permalink
Browse files

Add the "getters" Repository.path and Repository.workdir

  • Loading branch information...
1 parent 858adab commit bed8c13757d598110f9f65bef492873ade46563f David Versmisse committed Apr 28, 2011
Showing with 48 additions and 0 deletions.
  1. +24 −0 pygit2.c
  2. +24 −0 test/test_repository.py
View
@@ -342,6 +342,25 @@ Repository_get_index(Repository *self, void *closure) {
}
static PyObject *
+Repository_get_path(Repository *self, void *closure) {
+ const char *c_path;
+
+ c_path = git_repository_path(self->repo);
+ return PyString_FromString(c_path);
+}
+
+static PyObject *
+Repository_get_workdir(Repository *self, void *closure) {
+ const char *c_path;
+
+ c_path = git_repository_workdir(self->repo);
+ if (c_path == NULL)
+ Py_RETURN_NONE;
+
+ return PyString_FromString(c_path);
+}
+
+static PyObject *
Repository_walk(Repository *self, PyObject *args)
{
PyObject *value;
@@ -643,6 +662,11 @@ static PyMethodDef Repository_methods[] = {
static PyGetSetDef Repository_getseters[] = {
{"index", (getter)Repository_get_index, NULL, "index file. ", NULL},
+ {"path", (getter)Repository_get_path, NULL,
+ "The normalized path to the git repository.", NULL},
+ {"workdir", (getter)Repository_get_workdir, NULL,
+ "The normalized path to the working directory of the repository. "
+ "If the repository is bare, None will be returned.", NULL},
{NULL}
};
View
@@ -31,6 +31,7 @@
import binascii
import unittest
+from os.path import join, abspath
import pygit2
import utils
@@ -75,6 +76,29 @@ def test_lookup_commit(self):
'This commit has some additional text.\n'),
commit.message)
+ def test_get_path(self):
+ directory = abspath(self.repo.path)
+ expected = abspath(join(self._temp_dir, 'testrepo.git'))
+ self.assertEqual(directory, expected)
+
+ def test_get_workdir(self):
+ self.assertEqual(self.repo.workdir, None)
+
+
+
+class RepositoryTest_II(utils.RepoTestCase):
+
+ def test_get_path(self):
+ directory = abspath(self.repo.path)
+ expected = abspath(join(self._temp_dir, 'testrepo', '.git'))
+ self.assertEqual(directory, expected)
+
+ def test_get_workdir(self):
+ directory = abspath(self.repo.workdir)
+ expected = abspath(join(self._temp_dir, 'testrepo'))
+ self.assertEqual(directory, expected)
+
+
if __name__ == '__main__':
unittest.main()

0 comments on commit bed8c13

Please sign in to comment.