Skip to content

Commit e28c06f

Browse files
committed
Remote: allow access to the push url
1 parent 7ef2378 commit e28c06f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/remote.c

+37
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,42 @@ Remote_url__set__(Remote *self, PyObject* py_url)
278278
return -1;
279279
}
280280

281+
PyDoc_STRVAR(Remote_push_url__doc__, "Push url of the remote");
282+
283+
284+
PyObject *
285+
Remote_push_url__get__(Remote *self)
286+
{
287+
const char *url;
288+
289+
url = git_remote_pushurl(self->remote);
290+
if (!url)
291+
Py_RETURN_NONE;
292+
293+
return to_unicode(url, NULL, NULL);
294+
}
295+
296+
297+
int
298+
Remote_push_url__set__(Remote *self, PyObject* py_url)
299+
{
300+
int err;
301+
char* url = NULL;
302+
303+
url = py_str_to_c_str(py_url, NULL);
304+
if (url != NULL) {
305+
err = git_remote_set_pushurl(self->remote, url);
306+
free(url);
307+
308+
if (err == GIT_OK)
309+
return 0;
310+
311+
Error_set(err);
312+
}
313+
314+
return -1;
315+
}
316+
281317

282318
PyDoc_STRVAR(Remote_refspec_count__doc__, "Number of refspecs.");
283319

@@ -452,6 +488,7 @@ PyMethodDef Remote_methods[] = {
452488
PyGetSetDef Remote_getseters[] = {
453489
GETSET(Remote, name),
454490
GETSET(Remote, url),
491+
GETSET(Remote, push_url),
455492
GETTER(Remote, refspec_count),
456493
{NULL}
457494
};

test/test_remote.py

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_remote_create(self):
5050
self.assertEqual(type(remote), pygit2.Remote)
5151
self.assertEqual(name, remote.name)
5252
self.assertEqual(url, remote.url)
53+
self.assertEqual(None, remote.push_url)
5354

5455
self.assertRaises(ValueError, self.repo.create_remote, *(name, url))
5556

@@ -74,6 +75,10 @@ def test_remote_set_url(self):
7475

7576
self.assertRaisesAssign(ValueError, remote, 'url', '')
7677

78+
remote.push_url = new_url
79+
self.assertEqual(new_url, remote.push_url)
80+
self.assertRaisesAssign(ValueError, remote, 'push_url', '')
81+
7782

7883
def test_refspec(self):
7984
remote = self.repo.remotes[0]

0 commit comments

Comments
 (0)