예제 #1
0
    def test_sync_off_missing_master(self):
        # sync a repo without a master branch using default method.
        demo_path = join(self.testdir, 'demo')
        util.create_demo_git_repo(
            demo_path, 'refs/heads/alternative', 'refs/heads/new')

        new_path = join(self.testdir, 'new')
        item = DummyItem(new_path)
        self.backend.install(item)
        results = self.backend._sync_identifier(new_path, demo_path)
        self.assertEqual(results, [
            ('refs/heads/alternative',
                (True, 'Created new branch: refs/heads/alternative')),
            ('refs/heads/new',
                (True, 'Created new branch: refs/heads/new')),
        ])

        storage = self.backend.acquire(item)
        storage.checkout('refs/heads/alternative')
        self.assertEqual(storage.listdir(''), [
            'file1', 'file2'])
        storage.checkout('refs/heads/new')
        self.assertEqual(storage.listdir(''), [
            'file1', 'file2', 'file3', 'nested'])
예제 #2
0
    def test_010_storage_base(self):
        item = DummyItem(self.testdir)
        revs, fulllist = util.create_demo_git_repo(self.testdir)

        storage = GitStorage(item)
        result = storage.files()
        self.assertEqual(result, fulllist)
        entries = storage.listdir('')
        self.assertEqual(entries, ['file1', 'file2', 'file3', 'nested'])

        self.assertEqual(storage.rev, revs[-1])
        self.assertEqual(storage.shortrev, revs[-1][:12])

        info = storage.pathinfo('nested')
        self.assertEqual(info['size'], 0)
        self.assertEqual(info['type'], 'folder')

        entries = storage.listdir('nested')
        self.assertEqual(entries, ['deep'])

        info = storage.pathinfo('file1')
        self.assertEqual(info['size'], 38)
        self.assertEqual(info['type'], 'file')

        with self.assertRaises(PathNotFoundError):
            storage.pathinfo('nosuchpath')

        with self.assertRaises(PathNotFoundError):
            storage.listdir('nosuchpath')

        with self.assertRaises(PathNotDirError):
            storage.listdir('file1')

        with self.assertRaises(PathNotFileError):
            storage.file('nested')

        with self.assertRaises(PathNotFoundError):
            storage.pathinfo('nested/deep/nosuchpath')

        with self.assertRaises(PathNotFoundError):
            storage.listdir('nested/deep/nosuchpath')

        with self.assertRaises(PathNotDirError):
            storage.listdir('nested/deep/dir/file')

        with self.assertRaises(PathNotFileError):
            storage.file('nested/deep/dir')

        logs = storage.log('HEAD', 10)
        self.assertEqual(len(logs), 4)
        self.assertEqual(logs[0]['author'], u'user3')
        self.assertEqual(logs[1]['author'], u'user3')
        self.assertEqual(logs[2]['author'], u'user2')
        self.assertEqual(logs[3]['author'], u'user1')

        self.assertTrue(isinstance(logs[0]['date'], str))

        logs = storage.log(None, 2)
        self.assertEqual(len(logs), 2)

        storage.checkout(revs[0])
        self.assertEqual(storage.rev, revs[0])

        with self.assertRaises(PathNotFoundError):
            # normally won't be traversed, but for completeness, test
            # that getting an object with a type that is not expected
            # should fail.
            storage._get_obj('file1', DummyItem)