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.
This commit is contained in:
Carlos Martín Nieto
2014-04-14 17:19:36 +02:00
parent d7d0eb37c3
commit 7ed89b0aab
2 changed files with 4 additions and 0 deletions

View File

@@ -144,6 +144,9 @@ class Remote(object):
@name.setter
def name(self, value):
if not value:
raise ValueError("New remote name must be a non-empty string")
err = C.git_remote_rename(self._remote, to_str(value), ffi.NULL, ffi.NULL)
check_error(err)

View File

@@ -65,6 +65,7 @@ class RepositoryTest(utils.RepoTestCase):
self.assertEqual('new', remote.name)
self.assertRaisesAssign(ValueError, remote, 'name', '')
self.assertRaisesAssign(ValueError, remote, 'name', None)
def test_remote_set_url(self):