added setter for remote fetchspec

This commit is contained in:
Nico von Geyso 2013-02-16 20:46:21 +01:00
parent ee32acdf39
commit 4873529129
2 changed files with 35 additions and 2 deletions

@ -123,7 +123,7 @@ 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");
"Name of the remote source and destination fetch refspecs\n");
PyObject *
@ -146,12 +146,39 @@ Remote_fetchspec__get__(Remote *self)
return Error_set(GIT_ENOTFOUND);
}
int
Remote_fetchspec__set__(Remote *self, PyObject* py_tuple)
{
int err;
size_t length = 0;
char* src = NULL, *dst = NULL, *buf = NULL;
if (!PyArg_ParseTuple(py_tuple, "ss", &src, &dst))
return -1;
// length is strlen('+' + src + ':' + dst) and Null-Byte
length = strlen(src) + strlen(dst) + 3;
buf = (char*) calloc(length, sizeof(char));
if (buf != NULL) {
sprintf(buf, "+%s:%s", src, dst);
err = git_remote_set_fetchspec(self->remote, buf);
free(buf);
if (err == GIT_OK)
return 0;
Error_set_exc(PyExc_ValueError);
}
return -1;
}
PyGetSetDef Remote_getseters[] = {
GETSET(Remote, name),
GETSET(Remote, url),
GETSET(Remote, url),
GETTER(Remote, fetchspec),
GETSET(Remote, fetchspec),
{NULL}
};

@ -77,6 +77,12 @@ class RepositoryTest(utils.RepoTestCase):
self.assertEqual(REMOTE_FETCHSPEC_SRC, remote.fetchspec[0])
self.assertEqual(REMOTE_FETCHSPEC_DST, remote.fetchspec[1])
new_fetchspec = ('refs/foo/*','refs/remotes/foo/*')
remote.fetchspec = new_fetchspec
self.assertEqual(new_fetchspec[0], remote.fetchspec[0])
self.assertEqual(new_fetchspec[1], remote.fetchspec[1])
def test_remote_list(self):
self.assertEqual(1, len(self.repo.remotes))
remote = self.repo.remotes[0]