# HG changeset patch # User Anton Agafonov # Date 1353958714 28800 # Node ID cf53cfaaa0505ef59cfe559a644dbe91e4f39c0b # Parent 1bdd075a490a4623a1edf0bbc52a961f4cd52b73 Fixes bug #358. Display correct error message if a svn pre-commit hook blocks the push diff --git a/hgsubversion/pushmod.py b/hgsubversion/pushmod.py --- a/hgsubversion/pushmod.py +++ b/hgsubversion/pushmod.py @@ -210,6 +210,9 @@ def commit(ui, repo, rev_ctx, meta, base raise hgutil.Abort('Outgoing changesets parent is not at ' 'subversion HEAD\n' '(pull again and rebase on a newer revision)') + elif len(e.args) > 0 and e.args[1] == svnwrap.ERR_REPOS_HOOK_FAILURE: + # Special handling for svn hooks blocking error + raise hgutil.Abort(e.args[0]) else: raise diff --git a/hgsubversion/svnwrap/subvertpy_wrapper.py b/hgsubversion/svnwrap/subvertpy_wrapper.py --- a/hgsubversion/svnwrap/subvertpy_wrapper.py +++ b/hgsubversion/svnwrap/subvertpy_wrapper.py @@ -58,6 +58,7 @@ ERR_FS_TXN_OUT_OF_DATE = subvertpy.ERR_F ERR_INCOMPLETE_DATA = subvertpy.ERR_INCOMPLETE_DATA ERR_RA_DAV_PATH_NOT_FOUND = subvertpy.ERR_RA_DAV_PATH_NOT_FOUND ERR_RA_DAV_REQUEST_FAILED = subvertpy.ERR_RA_DAV_REQUEST_FAILED +ERR_REPOS_HOOK_FAILURE = subvertpy.ERR_REPOS_HOOK_FAILURE SSL_UNKNOWNCA = subvertpy.SSL_UNKNOWNCA SSL_CNMISMATCH = subvertpy.SSL_CNMISMATCH SSL_NOTYETVALID = subvertpy.SSL_NOTYETVALID diff --git a/hgsubversion/svnwrap/svn_swig_wrapper.py b/hgsubversion/svnwrap/svn_swig_wrapper.py --- a/hgsubversion/svnwrap/svn_swig_wrapper.py +++ b/hgsubversion/svnwrap/svn_swig_wrapper.py @@ -42,6 +42,7 @@ ERR_FS_NOT_FOUND = core.SVN_ERR_FS_NOT_F ERR_FS_TXN_OUT_OF_DATE = core.SVN_ERR_FS_TXN_OUT_OF_DATE ERR_INCOMPLETE_DATA = core.SVN_ERR_INCOMPLETE_DATA ERR_RA_DAV_REQUEST_FAILED = core.SVN_ERR_RA_DAV_REQUEST_FAILED +ERR_REPOS_HOOK_FAILURE = core.SVN_ERR_REPOS_HOOK_FAILURE SSL_UNKNOWNCA = core.SVN_AUTH_SSL_UNKNOWNCA SSL_CNMISMATCH = core.SVN_AUTH_SSL_CNMISMATCH SSL_NOTYETVALID = core.SVN_AUTH_SSL_NOTYETVALID diff --git a/tests/run.py b/tests/run.py --- a/tests/run.py +++ b/tests/run.py @@ -19,6 +19,7 @@ def tests(): import test_fetch_symlinks import test_fetch_truncated import test_hooks + import test_svn_pre_commit_hooks import test_pull import test_pull_fallback import test_push_command diff --git a/tests/test_svn_pre_commit_hooks.py b/tests/test_svn_pre_commit_hooks.py new file mode 100644 --- /dev/null +++ b/tests/test_svn_pre_commit_hooks.py @@ -0,0 +1,34 @@ +import os +import sys +import test_util +import unittest + +from mercurial import hg +from mercurial import commands +from mercurial import util + + +class TestSvnPreCommitHooks(test_util.TestBase): + def setUp(self): + super(TestSvnPreCommitHooks, self).setUp() + self.repo_path = self.load_and_fetch('single_rev.svndump')[1] + # creating pre-commit hook that doesn't allow any commit + hook_file_name = os.path.join( + self.repo_path, 'hooks', 'pre-commit' + ) + hook_file = open(hook_file_name, 'w') + hook_file.write( + '#!/bin/sh\n' + 'echo "Commits are not allowed" >&2; exit 1;\n' + ) + hook_file.close() + os.chmod(hook_file_name, 0755) + + def test_push_with_pre_commit_hooks(self): + changes = [('narf/a', 'narf/a', 'ohai',), + ] + self.commitchanges(changes) + self.assertRaises(util.Abort, self.pushrevisions) + +def suite(): + return unittest.findTestCases(sys.modules[__name__])