Anton Agafonov avatar Anton Agafonov committed 590762a

Fixes bug #358. Display correct error message if a svn pre-commit hook blocks the push

Comments (0)

Files changed (7)

hgsubversion/pushmod.py

             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
 

hgsubversion/svnwrap/subvertpy_wrapper.py

 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

hgsubversion/svnwrap/svn_swig_wrapper.py

 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

tests/fixtures/pre_commit_hooks.sh

+#!/bin/sh
+
+mkdir temp
+cd temp
+
+mkdir project-orig
+cd project-orig
+mkdir trunk branches tags
+cd ..
+
+svnadmin create testrepo
+svnurl=file://`pwd`/testrepo
+svn import --username equeny project-orig $svnurl -m "Empty dirs."
+
+svn co $svnurl project
+cd project
+echo 'file: alpha' > trunk/alpha
+svn add trunk/alpha
+svn ci --username durin -m 'Add alpha'
+echo 'Data of beta' > trunk/beta
+svn add trunk/beta
+svn ci --username durin -m 'Add beta'
+svn up
+svn cp trunk branches/the_branch
+svn ci --username durin -m 'Make a branch'
+cd ..
+
+echo '#!/bin/sh
+echo "Commits are not allowed" >&2; exit 1;
+' > `pwd`/testrepo/hooks/pre-commit
+chmod +x `pwd`/testrepo/hooks/pre-commit
+
+tar cz -C testrepo -f ../pre_commit_hooks.tar.gz .
Add a comment to this file

tests/fixtures/pre_commit_hooks.tar.gz

Binary file added.

     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

tests/test_svn_pre_commit_hooks.py

+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('pre_commit_hooks.tar.gz')[1]
+
+    def test_push_with(self):
+        changes = [('narf/a', 'narf/a', 'ohai',),
+                   ]
+        self.commitchanges(changes)
+        self.assertRaises(util.Abort, self.pushrevisions)
+
+def suite():
+    return unittest.findTestCases(sys.modules[__name__])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.