Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions quit/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def push(self, remote_name='origin', ref='refs/heads/master:refs/heads/master'):
for remote in self._repository.remotes:
if remote.name == remote_name:
remote.push([ref], callbacks=self.callback)
if self.callback.push_error is not None:
raise self.callback.push_error
return
raise QuitGitPushError("There is no remote \"{}\".", remote_name)

Expand Down Expand Up @@ -554,3 +556,18 @@ def credentials(self, url, username_from_url, allowed_types):
)
else:
raise Exception("Only unsupported credential types allowed by remote end")

def push_update_reference(self, refname, message):
"""This callback is called for a push operation.

In the case, that the remote rejects a push, message will be set.
Because we can't raise an Exception here, we have to write it to self.push_error, thus it is
important to check on the callback object if push_error is not None after a push.
"""
self.push_error = None
if message:
self.push_error = QuitGitPushError(
"The reference \"{}\" could not be pushed. Remote told us: {}".format(
refname.decode("utf-8"), message))
return -1
pass
20 changes: 19 additions & 1 deletion tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def testPushRepoWithRemoteName(self):

def testPushRepoNotConfiguredNamedRemote(self):
"""Test if the push failes if the specified remote was not defined."""
with TemporaryRepository(True) as remote:
with TemporaryRepository(is_bare=True) as remote:
graphContent = """
<http://ex.org/x> <http://ex.org/y> <http://ex.org/z> <http://example.org/> ."""
with TemporaryRepositoryFactory().withGraph("http://example.org/", graphContent) as local:
Expand Down Expand Up @@ -316,6 +316,24 @@ def testPushRepoWithDivergedRemote(self):
with self.assertRaises(pygit2.GitError):
quitRepo.push()

@unittest.skip("requires a remote with pre-receive hook")
def testPushRepoWithRemoteReject(self):
"""Test for an exception, if the remote repositories rejects a push.

CAUTION: This test is disabled, because it requires a remote with pre-receive hook.
Unfortunately the libgit2 does not execute pre-receive hooks on local repositories.
"""
graphContent = """
<http://ex.org/x> <http://ex.org/y> <http://ex.org/z> <http://example.org/> ."""
with TemporaryRepositoryFactory().withGraph("http://example.org/", graphContent) as local:
local.remotes.create("origin", "ssh://git@git.docker/testing.git")
quitRepo = quit.git.Repository(local.workdir)

self.assertFalse(local.is_empty)

with self.assertRaises(QuitGitPushError):
quitRepo.push()

def testRepositoryIsEmpty(self):
"""Test that adding data causes a new commit."""
self.addfile()
Expand Down