Skip to content

Commit 7ed89b0

Browse files
committed
Remote: protect against invalid input on rename
The C API expects a non-NULL new name and raises an assertion if we don't protect against such input, so let's guard against falsy values, which also takes care of the empty string, which is also not valid input.
1 parent d7d0eb3 commit 7ed89b0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

pygit2/remote.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ def name(self):
144144

145145
@name.setter
146146
def name(self, value):
147+
if not value:
148+
raise ValueError("New remote name must be a non-empty string")
149+
147150
err = C.git_remote_rename(self._remote, to_str(value), ffi.NULL, ffi.NULL)
148151
check_error(err)
149152

test/test_remote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def test_remote_rename(self):
6565
self.assertEqual('new', remote.name)
6666

6767
self.assertRaisesAssign(ValueError, remote, 'name', '')
68+
self.assertRaisesAssign(ValueError, remote, 'name', None)
6869

6970

7071
def test_remote_set_url(self):

0 commit comments

Comments
 (0)