Skip to content

Commit 4c28c48

Browse files
committed
Merge remote-tracking branch 'carlos/push-url'
2 parents de5244d + e28c06f commit 4c28c48

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/remote.c

+44-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,13 @@ PyDoc_STRVAR(Remote_url__doc__, "Url of the remote");
505505
PyObject *
506506
Remote_url__get__(Remote *self)
507507
{
508-
return to_unicode(git_remote_url(self->remote), NULL, NULL);
508+
const char *url;
509+
510+
url = git_remote_url(self->remote);
511+
if (!url)
512+
Py_RETURN_NONE;
513+
514+
return to_unicode(url, NULL, NULL);
509515
}
510516

511517

@@ -529,6 +535,42 @@ Remote_url__set__(Remote *self, PyObject* py_url)
529535
return -1;
530536
}
531537

538+
PyDoc_STRVAR(Remote_push_url__doc__, "Push url of the remote");
539+
540+
541+
PyObject *
542+
Remote_push_url__get__(Remote *self)
543+
{
544+
const char *url;
545+
546+
url = git_remote_pushurl(self->remote);
547+
if (!url)
548+
Py_RETURN_NONE;
549+
550+
return to_unicode(url, NULL, NULL);
551+
}
552+
553+
554+
int
555+
Remote_push_url__set__(Remote *self, PyObject* py_url)
556+
{
557+
int err;
558+
char* url = NULL;
559+
560+
url = py_str_to_c_str(py_url, NULL);
561+
if (url != NULL) {
562+
err = git_remote_set_pushurl(self->remote, url);
563+
free(url);
564+
565+
if (err == GIT_OK)
566+
return 0;
567+
568+
Error_set(err);
569+
}
570+
571+
return -1;
572+
}
573+
532574

533575
PyDoc_STRVAR(Remote_refspec_count__doc__, "Number of refspecs.");
534576

@@ -702,6 +744,7 @@ PyMethodDef Remote_methods[] = {
702744
PyGetSetDef Remote_getseters[] = {
703745
GETSET(Remote, name),
704746
GETSET(Remote, url),
747+
GETSET(Remote, push_url),
705748
GETTER(Remote, refspec_count),
706749
{NULL}
707750
};

test/test_remote.py

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def test_remote_create(self):
5151
self.assertEqual(type(remote), pygit2.Remote)
5252
self.assertEqual(name, remote.name)
5353
self.assertEqual(url, remote.url)
54+
self.assertEqual(None, remote.push_url)
5455

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

@@ -75,6 +76,10 @@ def test_remote_set_url(self):
7576

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

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

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

0 commit comments

Comments
 (0)