You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/09/26 18:19:46 UTC
[9/9] git commit: [#2809] Copy existing svn hooks when cloning a
local repo
[#2809] Copy existing svn hooks when cloning a local repo
Signed-off-by: Cory Johns <jo...@geek.net>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/b4ab5ec9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b4ab5ec9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b4ab5ec9
Branch: refs/heads/master
Commit: b4ab5ec95a8834814df4ac90cdb80280f494146f
Parents: 3f2cb4d
Author: Cory Johns <jo...@geek.net>
Authored: Thu Sep 13 20:48:12 2012 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Wed Sep 26 16:18:55 2012 +0000
----------------------------------------------------------------------
ForgeSVN/forgesvn/model/svn.py | 24 +++++++++++++--
.../forgesvn/tests/data/testsvn/hooks/post-commit | 3 +-
.../tests/data/testsvn/hooks/post-revprop-change | 1 +
.../tests/data/testsvn/hooks/pre-revprop-change | 1 +
ForgeSVN/forgesvn/tests/model/test_repository.py | 13 ++++++++
5 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b4ab5ec9/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 2d530bb..ab96f8f 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -8,6 +8,7 @@ from subprocess import Popen, PIPE
from hashlib import sha1
from cStringIO import StringIO
from datetime import datetime
+from glob import glob
import tg
import pysvn
@@ -87,8 +88,14 @@ class SVNCalledProcessError(Exception):
class SVNImplementation(M.RepositoryImplementation):
post_receive_template = string.Template(
'#!/bin/bash\n'
- '# The following line is required for site integration, do not remove/modify\n'
- 'curl -s $url\n')
+ '# The following is required for site integration, do not remove/modify.\n'
+ '# Place user hook code in post-commit-user and it will be called from here.\n'
+ 'curl -s $url\n'
+ '\n'
+ 'DIR="$$(dirname "$${BASH_SOURCE[0]}")"\n'
+ 'if [ -x $$DIR/post-commit-user ]; then'
+ ' exec $$DIR/post-commit-user\n'
+ 'fi')
def __init__(self, repo):
self._repo = repo
@@ -168,7 +175,7 @@ class SVNImplementation(M.RepositoryImplementation):
c.app.config.options['checkout_url'])):
c.app.config.options['checkout_url'] = ""
self._repo.refresh(notify=False)
- self._setup_special_files()
+ self._setup_special_files(source_url)
def refresh_heads(self):
info = self._svn.info2(
@@ -426,6 +433,17 @@ class SVNImplementation(M.RepositoryImplementation):
with open(fn, 'wb') as fp:
fp.write('#!/bin/sh\n')
os.chmod(fn, 0755)
+ # copy existing hooks if source path is given and exists
+ if source_path and source_path.startswith('file://'):
+ source_path = source_path[7:]
+ if source_path is not None and os.path.exists(source_path):
+ for hook in glob(os.path.join(source_path, 'hooks/*')):
+ filename = os.path.basename(hook)
+ target_filename = filename
+ if filename == 'post-commit':
+ target_filename = 'post-commit-user'
+ target = os.path.join(self._repo.full_fs_path, 'hooks', target_filename)
+ shutil.copyfile(hook, target)
def _revno(self, oid):
return int(oid.split(':')[1])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b4ab5ec9/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-commit
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-commit b/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-commit
index 4a53285..67000e9 100755
--- a/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-commit
+++ b/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-commit
@@ -1,2 +1 @@
-#!/bin/bash
-curl -s http://localhost:8080/p/test/svn/refresh
+post-commit
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b4ab5ec9/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-revprop-change
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-revprop-change b/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-revprop-change
new file mode 100644
index 0000000..03d1e73
--- /dev/null
+++ b/ForgeSVN/forgesvn/tests/data/testsvn/hooks/post-revprop-change
@@ -0,0 +1 @@
+post-revprop-change
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b4ab5ec9/ForgeSVN/forgesvn/tests/data/testsvn/hooks/pre-revprop-change
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/data/testsvn/hooks/pre-revprop-change b/ForgeSVN/forgesvn/tests/data/testsvn/hooks/pre-revprop-change
new file mode 100644
index 0000000..c3e2d75
--- /dev/null
+++ b/ForgeSVN/forgesvn/tests/data/testsvn/hooks/pre-revprop-change
@@ -0,0 +1 @@
+pre-revprop-change
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b4ab5ec9/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index e4d84c6..808c4ac 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -122,6 +122,19 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
repo.init()
repo._impl.clone_from('file://' + repo_path)
assert len(repo.log())
+ assert os.path.exists('/tmp/testsvn/hooks/pre-revprop-change')
+ with open('/tmp/testsvn/hooks/pre-revprop-change') as f: c = f.read()
+ self.assertEqual(c, 'pre-revprop-change\n')
+ assert os.path.exists('/tmp/testsvn/hooks/post-revprop-change')
+ with open('/tmp/testsvn/hooks/post-revprop-change') as f: c = f.read()
+ self.assertEqual(c, 'post-revprop-change\n')
+ assert os.path.exists('/tmp/testsvn/hooks/post-commit-user')
+ with open('/tmp/testsvn/hooks/post-commit-user') as f: c = f.read()
+ self.assertEqual(c, 'post-commit\n')
+ assert os.path.exists('/tmp/testsvn/hooks/post-commit')
+ with open('/tmp/testsvn/hooks/post-commit') as f: c = f.read()
+ self.assertIn('curl -s http://localhost//auth/refresh_repo/p/test/src/\n', c)
+ self.assertIn('exec $DIR/post-commit-user\n', c)
shutil.rmtree(dirname)
def test_index(self):