diff --git a/src/remote.c b/src/remote.c index f8edbc7..dc553f3 100644 --- a/src/remote.c +++ b/src/remote.c @@ -91,7 +91,7 @@ Remote_name__set__(Remote *self, PyObject* py_name) } -PyDoc_STRVAR(Remote_url__doc__, "Url of the remote refspec"); +PyDoc_STRVAR(Remote_url__doc__, "Url of the remote"); PyObject * Remote_url__get__(Remote *self) @@ -120,9 +120,38 @@ Remote_url__set__(Remote *self, PyObject* py_url) } +PyDoc_STRVAR(Remote_fetchspec__doc__, + "= (source:str, destination:str)\n" + "\n" + "Name of the remote source and destination refspecs\n"); + + +PyObject * +Remote_fetchspec__get__(Remote *self) +{ + PyObject* py_tuple = NULL; + const git_refspec * refspec; + + refspec = git_remote_fetchspec(self->remote); + if (refspec != NULL) { + py_tuple = Py_BuildValue( + "(ss)", + git_refspec_src(refspec), + git_refspec_dst(refspec) + ); + + return py_tuple; + } + + return Error_set(GIT_ENOTFOUND); +} + + PyGetSetDef Remote_getseters[] = { GETSET(Remote, name), GETSET(Remote, url), + GETSET(Remote, url), + GETTER(Remote, fetchspec), {NULL} }; diff --git a/test/test_remote.py b/test/test_remote.py index 2ca347f..b7595eb 100644 --- a/test/test_remote.py +++ b/test/test_remote.py @@ -33,6 +33,8 @@ from . import utils REMOTE_NAME = 'origin' REMOTE_URL = 'git://github.com/libgit2/pygit2.git' +REMOTE_FETCHSPEC_SRC = 'refs/heads/*' +REMOTE_FETCHSPEC_DST = 'refs/remotes/origin/*' class RepositoryTest(utils.RepoTestCase): def test_remote_create(self): @@ -69,6 +71,12 @@ class RepositoryTest(utils.RepoTestCase): self.assertRaisesAssign(ValueError, remote, 'url', '') + def test_remote_fetchspec(self): + remote = self.repo.remotes[0] + + self.assertEqual(REMOTE_FETCHSPEC_SRC, remote.fetchspec[0]) + self.assertEqual(REMOTE_FETCHSPEC_DST, remote.fetchspec[1]) + def test_remote_list(self): self.assertEqual(1, len(self.repo.remotes)) remote = self.repo.remotes[0]