allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [2/2] git commit: [#5459] Added hot-copy to git
Date Thu, 21 Feb 2013 23:03:06 GMT
Updated Branches:
  refs/heads/master a3e82f03e -> c3f622ef3


[#5459] Added hot-copy to git

Signed-off-by: Cory Johns <johnsca@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/11e8813f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/11e8813f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/11e8813f

Branch: refs/heads/master
Commit: 11e8813ffed734ecb213fd4027f9cbba20d5487e
Parents: a3e82f0
Author: Cory Johns <johnsca@geek.net>
Authored: Wed Feb 13 23:54:51 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Thu Feb 21 22:53:57 2013 +0000

----------------------------------------------------------------------
 ForgeGit/forgegit/model/git_repo.py              |   21 ++++-
 ForgeGit/forgegit/tests/model/test_repository.py |   72 ++++++++++++-----
 2 files changed, 68 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e8813f/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 7154a6d..4a0942e 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -15,6 +15,7 @@ import gitdb
 from pylons import app_globals as g
 from pylons import tmpl_context as c
 from pymongo.errors import DuplicateKeyError
+from paste.deploy.converters import asbool
 
 from ming.base import Object
 from ming.orm import Mapper, session, mapper
@@ -93,6 +94,11 @@ class GitImplementation(M.RepositoryImplementation):
         self._setup_special_files()
         self._repo.status = 'ready'
 
+    def can_hotcopy(self, source_url):
+        enabled = asbool(tg.config.get('scm.git.hotcopy', True))
+        is_local = os.path.exists(source_url)
+        return enabled and is_local
+
     def clone_from(self, source_url):
         '''Initialize a repo as a clone of another'''
         self._repo.status = 'cloning'
@@ -103,10 +109,17 @@ class GitImplementation(M.RepositoryImplementation):
             fullname = self._setup_paths(create_repo_dir=False)
             if os.path.exists(fullname):
                 shutil.rmtree(fullname)
-            repo = git.Repo.clone_from(
-                source_url,
-                to_path=fullname,
-                bare=True)
+            if self.can_hotcopy(source_url):
+                shutil.copytree(source_url, fullname)
+                post_receive = os.path.join(self._repo.full_fs_path, 'hooks', 'post-receive')
+                if os.path.exists(post_receive):
+                    os.rename(post_receive, post_receive + '-user')
+                repo = git.Repo(fullname)
+            else:
+                repo = git.Repo.clone_from(
+                    source_url,
+                    to_path=fullname,
+                    bare=True)
             self.__dict__['_git'] = repo
             self._setup_special_files(source_url)
         except:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e8813f/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 1906470..8ed46dd 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -5,6 +5,7 @@ import pkg_resources
 
 import mock
 from pylons import tmpl_context as c, app_globals as g
+import tg
 from ming.base import Object
 from ming.orm import ThreadLocalORMSession, session
 from nose.tools import assert_equal
@@ -147,28 +148,57 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
 
     @mock.patch('forgegit.model.git_repo.g.post_event')
     def test_clone(self, post_event):
-        repo = GM.Repository(
-            name='testgit.git',
-            fs_path='/tmp/',
-            url_path = '/test/',
-            tool = 'git',
-            status = 'creating')
-        repo_path = pkg_resources.resource_filename(
-            'forgegit', 'tests/data/testgit.git')
-        dirname = os.path.join(repo.fs_path, repo.name)
-        if os.path.exists(dirname):
+        with h.push_config(tg.config, **{'scm.git.hotcopy': 'False'}):
+            repo = GM.Repository(
+                name='testgit.git',
+                fs_path='/tmp/',
+                url_path = '/test/',
+                tool = 'git',
+                status = 'creating')
+            repo_path = pkg_resources.resource_filename(
+                'forgegit', 'tests/data/testgit.git')
+            dirname = os.path.join(repo.fs_path, repo.name)
+            if os.path.exists(dirname):
+                shutil.rmtree(dirname)
+            repo.init()
+            repo._impl.clone_from(repo_path)
+            assert len(repo.log())
+            assert not os.path.exists('/tmp/testgit.git/hooks/update')
+            assert not os.path.exists('/tmp/testgit.git/hooks/post-receive-user')
+            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)
+            shutil.rmtree(dirname)
+
+    @mock.patch('forgegit.model.git_repo.git.Repo.clone_from')
+    @mock.patch('forgegit.model.git_repo.g.post_event')
+    def test_hotcopy(self, post_event, clone_from):
+        with h.push_config(tg.config, **{'scm.git.hotcopy': 'True'}):
+            repo = GM.Repository(
+                name='testgit.git',
+                fs_path='/tmp/',
+                url_path = '/test/',
+                tool = 'git',
+                status = 'creating')
+            repo_path = pkg_resources.resource_filename(
+                'forgegit', 'tests/data/testgit.git')
+            dirname = os.path.join(repo.fs_path, repo.name)
+            if os.path.exists(dirname):
+                shutil.rmtree(dirname)
+            repo.init()
+            repo._impl.clone_from(repo_path)
+            assert not clone_from.called
+            assert len(repo.log())
+            assert os.path.exists('/tmp/testgit.git/hooks/update')
+            assert os.path.exists('/tmp/testgit.git/hooks/post-receive-user')
+            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)
             shutil.rmtree(dirname)
-        repo.init()
-        repo._impl.clone_from(repo_path)
-        assert len(repo.log())
-        assert not os.path.exists('/tmp/testgit.git/hooks/update')
-        assert not os.path.exists('/tmp/testgit.git/hooks/post-receive-user')
-        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)
-        shutil.rmtree(dirname)
 
     def test_index(self):
         i = self.repo.index()


Mime
View raw message