示例#1
0
 def test_clone(self, post_event):
     repo = GM.Repository(name='testgit.git',
                          fs_path=g.tmpdir + '/',
                          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(list(repo.log()))
     assert not os.path.exists(
         os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
     assert not os.path.exists(
         os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
     assert os.path.exists(
         os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
     assert os.stat(os.path.join(
         g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
     with open(os.path.join(g.tmpdir,
                            '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)
示例#2
0
    def test_paged_diffs_with_detect_copies(self):
        # setup
        h.set_context('test', 'src-weird', neighborhood='Projects')
        repo_dir = pkg_resources.resource_filename(
            'forgegit', 'tests/data')
        repo = GM.Repository(
            name='weird-chars.git',
            fs_path=repo_dir,
            url_path='/src-weird/',
            tool='git',
            status='creating')
        repo.refresh()
        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()

        diffs = repo.paged_diffs('346c52c1dddc729e2c2711f809336401f0ff925e')  # Test copy
        expected = {
            'added': [],
            'removed': [],
            'copied': [{'new': 'README.copy', 'old': 'README', 'ratio': 1.0}],
            'renamed': [],
            'changed': ['README'],
            'total': 2,
        }
        assert_equals(diffs, expected)
        diffs = repo.paged_diffs('3cb2bbcd7997f89060a14fe8b1a363f01883087f')  # Test rename
        expected = {
            'added': [],
            'removed': [],
            'copied': [],
            'renamed': [{'new': 'README', 'old': 'README-copy.md', 'ratio': 1.0}],
            'changed': [],
            'total': 1,
        }
        assert_equals(diffs, expected)
示例#3
0
 def test_hotcopy(self, clone_from):
     with h.push_config(tg.config, **{'scm.git.hotcopy': 'True'}):
         repo = GM.Repository(
             name='testgit.git',
             fs_path=g.tmpdir + '/',
             url_path='/test/',
             tool='git',
             status='creating')
         repo.app.config.options['hotcopy'] = True
         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(list(repo.log()))
         assert os.path.exists(
             os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
         assert os.path.exists(
             os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
         assert os.path.exists(
             os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
         assert os.stat(
             os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
         with open(os.path.join(g.tmpdir, '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)
示例#4
0
 def test_clone(self):
     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, copy_hooks=True)
     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)
     shutil.rmtree(dirname)
示例#5
0
 def test_init(self):
     repo = GM.Repository(name='testgit.git',
                          fs_path='/tmp/',
                          url_path='/test/',
                          tool='git',
                          status='creating')
     dirname = os.path.join(repo.fs_path, repo.name)
     if os.path.exists(dirname):
         shutil.rmtree(dirname)
     repo.init()
     shutil.rmtree(dirname)
示例#6
0
 def setup_with_tools(self):
     setup_global_objects()
     h.set_context('test', 'src-git', neighborhood='Projects')
     repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data')
     self.repo = GM.Repository(name='testgit.git',
                               fs_path=repo_dir,
                               url_path='/test/',
                               tool='git',
                               status='creating')
     self.repo.refresh()
     ThreadLocalORMSession.flush_all()
     ThreadLocalORMSession.close_all()
示例#7
0
 def test_is_empty(self):
     assert not self.repo.is_empty()
     with TempDirectory() as d:
         repo2 = GM.Repository(name='test',
                               fs_path=d.path,
                               url_path='/test/',
                               tool='git',
                               status='creating')
         repo2.init()
         assert repo2.is_empty()
         repo2.refresh()
         ThreadLocalORMSession.flush_all()
         assert repo2.is_empty()
示例#8
0
 def test_clone(self):
     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())
     shutil.rmtree(dirname)
示例#9
0
 def test_fork(self):
     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, copy_hooks=False)
     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)
示例#10
0
 def test_fork(self):
     repo = GM.Repository(
         name='testgit.git',
         fs_path=g.tmpdir + '/',
         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 os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
     assert not os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
     assert os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
     assert os.stat(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
示例#11
0
    def test_paged_diffs(self):
        # setup
        h.set_context('test', 'src-weird', neighborhood='Projects')
        repo_dir = pkg_resources.resource_filename(
            'forgegit', 'tests/data')
        repo = GM.Repository(
            name='weird-chars.git',
            fs_path=repo_dir,
            url_path='/src-weird/',
            tool='git',
            status='creating')
        repo.refresh()
        ThreadLocalORMSession.flush_all()
        ThreadLocalORMSession.close_all()

        # spaces and unicode filenames
        diffs = repo.paged_diffs('407950e8fba4dbc108ffbce0128ed1085c52cfd7')
        expected = {
            'removed': [],
            'changed': [],
            'renamed': [],
            'added': ['with space.txt', 'привіт.txt'],
            'copied': [],
            'total': 2,
        }
        assert_equals(diffs, expected)

        diffs = repo.paged_diffs('f3de6a0e7601cdde326054a1cc708afdc1dbe70b')
        expected = {
            'added': [],
            'removed': [],
            'copied': [],
            'renamed': [],
            'changed': ['привіт.txt'],
            'total': 1,
        }
        assert_equals(diffs, expected)

        # initial commit is special, but must work too
        diffs = repo.paged_diffs('afaa6d93eb5661fb04f8e10e9ba1039b7441a6c7')
        expected = {
            'added': ['README.md'],
            'removed': [],
            'changed': [],
            'copied': [],
            'renamed': [],
            'total': 1,
        }
        assert_equals(diffs, expected)

        # pagination
        diffs = repo.paged_diffs('407950e8fba4dbc108ffbce0128ed1085c52cfd7', start=0, end=1)
        expected = {
            'added': ['with space.txt'],
            'removed': [],
            'copied': [],
            'renamed': [],
            'changed': [],
            'total': 2,  # there are two total changes but result is limited to first
        }
        assert_equals(diffs, expected)
        diffs = repo.paged_diffs('407950e8fba4dbc108ffbce0128ed1085c52cfd7', start=1, end=2)
        expected = {
            'added': ['привіт.txt'],
            'removed': [],
            'copied': [],
            'renamed': [],
            'changed': [],
            'total': 2,  # there are two total changes but result is limited to second
        }
        assert_equals(diffs, expected)
        diffs = repo.paged_diffs('346c52c1dddc729e2c2711f809336401f0ff925e')  # Test copy
        expected = {
            'added': ['README.copy'],
            'removed': [],
            'copied': [],
            'renamed': [],
            'changed': ['README'],
            'total': 2,
        }
        assert_equals(diffs, expected)
        diffs = repo.paged_diffs('3cb2bbcd7997f89060a14fe8b1a363f01883087f')  # Test rename
        expected = {
            'added': ['README'],
            'removed': ['README-copy.md'],
            'copied': [],
            'renamed': [],
            'changed': [],
            'total': 2,
        }
        assert_equals(diffs, expected)
        diffs = repo.paged_diffs('616d24f8dd4e95cadd8e93df5061f09855d1a066')  # Test type change
        expected = {
            'added': [],
            'removed': [],
            'copied': [],
            'renamed': [],
            'changed': ['README.copy'],
            'total': 1,
        }
        assert_equals(diffs, expected)