Exemplo n.º 1
0
def init_repo(folders):
    if all(os.path.isdir(folder) for folder in folders):
        commit_id = '7f3a0b96aba5cf299ecc4e2985ec49f9bb7559ba'

    else:
        commit_id = None
        for folder in folders:
            if os.path.isdir(folder):
                shutil.rmtree(folder)

        folder = '/tmp/iemldb_test/tmp'
        if os.path.isdir(folder):
            shutil.rmtree(folder)

        print("Cloning IEML db : ", folder)
        GitInterface(folder=folder)

    gitdbs = []
    for f in folders:

        if not commit_id:
            print("Copying IEML db: ", f)

            shutil.copytree(folder, f)
            git = GitInterface(folder=f)
        else:
            git = GitInterface(folder=f)
            git.reset(commit_id)

        gitdbs.append(git)

    if not commit_id:
        shutil.rmtree('/tmp/iemldb_test/tmp')

    return gitdbs
Exemplo n.º 2
0
class TestGitInterface(unittest.TestCase):
    def setUp(self):
        # repo = pygit2.init_repository(REPO_TEST_PATH)
        self.git = GitInterface(folder=REPO_TEST_PATH)

    # def tearDown(self):
    #     shutil.rmtree(REPO_TEST_PATH)

    def test_checkout_at_commit(self):
        versions = [
            '148505dbea8ec25fa81162c7bdeed685986094a6',
            'f8f3c2882db71e8b70c6f1b73566fc53c877ea6e'
        ]

        # for version in versions:
        #     self.assertEqual(str(self.git.get_version()[1]), version)

        for version in versions:
            self.git.checkout(None, version)
            self.assertEqual(str(self.git.get_version()[1]), version)

    def test_reset(self):
        with open(os.path.join(REPO_TEST_PATH, "test"), 'w') as fp:
            fp.write("test\n")

        self.assertIn('test', self.git.repo.status())
        self.git.reset()
        self.assertDictEqual(self.git.repo.status(), {})

    def test_transaction(self):
        trans = DBTransactions(self.git,
                               pygit2.Signature('git', 'git'),
                               REPO_TEST_PATH_CACHE,
                               use_cache=True)
        trans.set_descriptors(script("E:"), "tags", {'fr': "test"})