Skip to content

Commit a92a453

Browse files
committed
Add unit test for issue #996
1 parent 3379f61 commit a92a453

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.cache/
22
/.eggs/
3+
/.envrc
34
/.tox/
45
/build/
56
/dist/

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build
1+
.PHONY: build html
22

33
build:
44
python setup.py build_ext --inplace -g

pygit2/errors.py

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def check_error(err, io=False):
3434
if err >= 0:
3535
return
3636

37+
# These are special error codes, they should never reach here
38+
test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH
39+
assert test, f'Unexpected error code {err}'
40+
3741
# Error message
3842
giterr = C.git_error_last()
3943
if giterr != ffi.NULL:

test/test_repository.py

+11
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,17 @@ def test_clone_with_credentials(self):
643643

644644
assert not repo.is_empty
645645

646+
@unittest.skipIf(utils.no_network(), "Requires network")
647+
def test_clone_bad_credentials(self):
648+
class MyCallbacks(pygit2.RemoteCallbacks):
649+
def credentials(self, url, username, allowed):
650+
raise RuntimeError('Unexpected error')
651+
652+
url = "https://github.com/github/github"
653+
with pytest.raises(RuntimeError) as exc:
654+
clone_repository(url, self._temp_dir, callbacks=MyCallbacks())
655+
assert str(exc.value) == 'Unexpected error'
656+
646657
def test_clone_with_checkout_branch(self):
647658
# create a test case which isolates the remote
648659
test_repo = clone_repository('./test/data/testrepo.git',

0 commit comments

Comments
 (0)