added setter for remote fetchspec
This commit is contained in:
31
src/remote.c
31
src/remote.c
@@ -123,7 +123,7 @@ Remote_url__set__(Remote *self, PyObject* py_url)
|
|||||||
PyDoc_STRVAR(Remote_fetchspec__doc__,
|
PyDoc_STRVAR(Remote_fetchspec__doc__,
|
||||||
"= (source:str, destination:str)\n"
|
"= (source:str, destination:str)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Name of the remote source and destination refspecs\n");
|
"Name of the remote source and destination fetch refspecs\n");
|
||||||
|
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
@@ -146,12 +146,39 @@ Remote_fetchspec__get__(Remote *self)
|
|||||||
return Error_set(GIT_ENOTFOUND);
|
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[] = {
|
PyGetSetDef Remote_getseters[] = {
|
||||||
GETSET(Remote, name),
|
GETSET(Remote, name),
|
||||||
GETSET(Remote, url),
|
GETSET(Remote, url),
|
||||||
GETSET(Remote, url),
|
GETSET(Remote, url),
|
||||||
GETTER(Remote, fetchspec),
|
GETSET(Remote, fetchspec),
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -77,6 +77,12 @@ class RepositoryTest(utils.RepoTestCase):
|
|||||||
self.assertEqual(REMOTE_FETCHSPEC_SRC, remote.fetchspec[0])
|
self.assertEqual(REMOTE_FETCHSPEC_SRC, remote.fetchspec[0])
|
||||||
self.assertEqual(REMOTE_FETCHSPEC_DST, remote.fetchspec[1])
|
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):
|
def test_remote_list(self):
|
||||||
self.assertEqual(1, len(self.repo.remotes))
|
self.assertEqual(1, len(self.repo.remotes))
|
||||||
remote = self.repo.remotes[0]
|
remote = self.repo.remotes[0]
|
||||||
|
Reference in New Issue
Block a user