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
[7/9] git commit: [#2809] Refactored and added permission checking to
copy hooks for git and svn
[#2809] Refactored and added permission checking to copy hooks for git and svn
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/1bbfd45d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1bbfd45d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1bbfd45d
Branch: refs/heads/master
Commit: 1bbfd45d0fb10fc7869a0ef71819a55526d31076
Parents: b4ab5ec
Author: Cory Johns <jo...@geek.net>
Authored: Fri Sep 14 17:17:51 2012 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Wed Sep 26 16:18:56 2012 +0000
----------------------------------------------------------------------
ForgeGit/forgegit/model/git_repo.py | 22 ++++++++------
ForgeGit/forgegit/tests/model/test_repository.py | 3 ++
ForgeSVN/forgesvn/model/svn.py | 26 +++++++++-------
ForgeSVN/forgesvn/tests/model/test_repository.py | 4 ++
4 files changed, 35 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 5ca4740..90df532 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -262,6 +262,18 @@ class GitImplementation(M.RepositoryImplementation):
def blob_size(self, blob):
return self._object(blob._id).data_stream.size
+ def _copy_hooks(self, source_path):
+ '''Copy existing hooks if source path is given and exists.'''
+ if source_path is None or not os.path.exists(source_path):
+ return
+ for hook in glob(os.path.join(source_path, 'hooks/*')):
+ filename = os.path.basename(hook)
+ target_filename = filename
+ if filename == 'post-receive':
+ target_filename = 'post-receive-user'
+ target = os.path.join(self._repo.full_fs_path, 'hooks', target_filename)
+ shutil.copy2(hook, target)
+
def _setup_hooks(self, source_path=None):
'Set up the git post-commit hook'
text = self.post_receive_template.substitute(
@@ -271,15 +283,7 @@ class GitImplementation(M.RepositoryImplementation):
with open(fn, 'w') as fp:
fp.write(text)
os.chmod(fn, 0755)
- # copy existing hooks if source path is given and exists
- 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-receive':
- target_filename = 'post-receive-user'
- target = os.path.join(self._repo.full_fs_path, 'hooks', target_filename)
- shutil.copyfile(hook, target)
+ self._copy_hooks(source_path)
def _object(self, oid):
evens = oid[::2]
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/ForgeGit/forgegit/tests/data/testgit.git/hooks/post-receive
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/data/testgit.git/hooks/post-receive b/ForgeGit/forgegit/tests/data/testgit.git/hooks/post-receive
old mode 100644
new mode 100755
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/ForgeGit/forgegit/tests/data/testgit.git/hooks/update
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/data/testgit.git/hooks/update b/ForgeGit/forgegit/tests/data/testgit.git/hooks/update
old mode 100644
new mode 100755
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 9c42aad..d365199 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -145,12 +145,15 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
repo._impl.clone_from(repo_path)
assert len(repo.log())
assert os.path.exists('/tmp/testgit.git/hooks/update')
+ assert os.access('/tmp/testgit.git/hooks/update', os.X_OK)
with open('/tmp/testgit.git/hooks/update') as f: c = f.read()
self.assertEqual(c, 'update\n')
assert os.path.exists('/tmp/testgit.git/hooks/post-receive-user')
+ assert os.access('/tmp/testgit.git/hooks/post-receive-user', os.X_OK)
with open('/tmp/testgit.git/hooks/post-receive-user') as f: c = f.read()
self.assertEqual(c, 'post-receive\n')
assert os.path.exists('/tmp/testgit.git/hooks/post-receive')
+ assert os.access('/tmp/testgit.git/hooks/post-receive', os.X_OK)
with open('/tmp/testgit.git/hooks/post-receive') as f: c = f.read()
self.assertIn('curl -s http://localhost//auth/refresh_repo/p/test/src-git/\n', c)
self.assertIn('exec $DIR/post-receive-user\n', c)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index ab96f8f..ebb04f1 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -420,6 +420,20 @@ class SVNImplementation(M.RepositoryImplementation):
return size
+ def _copy_hooks(self, source_path):
+ '''Copy existing hooks if source path is given and exists.'''
+ if source_path is not None and source_path.startswith('file://'):
+ source_path = source_path[7:]
+ if source_path is None or not os.path.exists(source_path):
+ return
+ 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.copy2(hook, target)
+
def _setup_hooks(self, source_path=None):
'Set up the post-commit and pre-revprop-change hooks'
text = self.post_receive_template.substitute(
@@ -433,17 +447,7 @@ 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)
+ self._copy_hooks(source_path)
def _revno(self, oid):
return int(oid.split(':')[1])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/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
old mode 100644
new mode 100755
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/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
old mode 100644
new mode 100755
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1bbfd45d/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 808c4ac..6ab766a 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -123,15 +123,19 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
repo._impl.clone_from('file://' + repo_path)
assert len(repo.log())
assert os.path.exists('/tmp/testsvn/hooks/pre-revprop-change')
+ assert os.access('/tmp/testsvn/hooks/pre-revprop-change', os.X_OK)
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')
+ assert os.access('/tmp/testsvn/hooks/post-revprop-change', os.X_OK)
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')
+ assert os.access('/tmp/testsvn/hooks/post-commit-user', os.X_OK)
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')
+ assert os.access('/tmp/testsvn/hooks/post-commit', os.X_OK)
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)