Add the "getters" Repository.path and Repository.workdir
This commit is contained in:
parent
858adab759
commit
bed8c13757
24
pygit2.c
24
pygit2.c
@ -341,6 +341,25 @@ Repository_get_index(Repository *self, void *closure) {
|
||||
return self->index;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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}
|
||||
};
|
||||
|
||||
|
@ -31,6 +31,7 @@ __author__ = 'dborowitz@google.com (Dave Borowitz)'
|
||||
|
||||
import binascii
|
||||
import unittest
|
||||
from os.path import join, abspath
|
||||
|
||||
import pygit2
|
||||
import utils
|
||||
@ -75,6 +76,29 @@ class RepositoryTest(utils.BareRepoTestCase):
|
||||
'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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user