def test_garbage_collect(self): '''Tests that git gc doesn't prune FETCH_HEAD''' parent_path = os.path.join(self.upstream_root, 'org/project1') repo = git.Repo(parent_path) change_ref = 'refs/changes/1/1' self.log.info('Creating a commit on %s', change_ref) repo.head.reference = repo.head.commit files = {"README": "creating fake commit\n"} for name, content in files.items(): file_name = os.path.join(parent_path, name) with open(file_name, 'a') as f: f.write(content) repo.index.add([file_name]) commit = repo.index.commit('Test commit') ref = git.refs.Reference(repo, change_ref) ref.set_commit(commit) self.log.info('Cloning parent repo') work_repo = Repo(parent_path, self.workspace_root, '*****@*****.**', 'User Name', '0', '0') self.log.info('Fetch %s', change_ref) work_repo.fetch(change_ref) self.log.info('Checkout master and run garbage collection') work_repo_object = work_repo.createRepoObject(None) work_repo.checkout('master') result = work_repo_object.git.gc('--prune=now') self.log.info(result) self.log.info('Dereferencing FETCH_HEAD') commit = work_repo_object.commit('FETCH_HEAD') self.assertIsNotNone(commit)
def test_ensure_cloned(self): parent_path = os.path.join(self.upstream_root, "org/project1") # Forge a repo having a submodule parent_repo = git.Repo(parent_path) parent_repo.git.submodule("add", os.path.join(self.upstream_root, "org/project2"), "subdir") parent_repo.index.commit("Adding project2 as a submodule in subdir") # git 1.7.8 changed .git from being a directory to a file pointing # to the parent repository /.git/modules/* self.assertTrue( os.path.exists(os.path.join(parent_path, "subdir", ".git")), msg=".git file in submodule should be a file" ) work_repo = Repo(parent_path, self.workspace_root, "*****@*****.**", "User Name") self.assertTrue( os.path.isdir(os.path.join(self.workspace_root, "subdir")), msg="Cloned repository has a submodule placeholder directory", ) self.assertFalse( os.path.exists(os.path.join(self.workspace_root, "subdir", ".git")), msg="Submodule is not initialized" ) sub_repo = Repo( os.path.join(self.upstream_root, "org/project2"), os.path.join(self.workspace_root, "subdir"), "*****@*****.**", "User Name", ) self.assertTrue( os.path.exists(os.path.join(self.workspace_root, "subdir", ".git")), msg="Cloned over the submodule placeholder", ) self.assertEquals( os.path.join(self.upstream_root, "org/project1"), work_repo.createRepoObject().remotes[0].url, message="Parent clone still point to upstream project1", ) self.assertEquals( os.path.join(self.upstream_root, "org/project2"), sub_repo.createRepoObject().remotes[0].url, message="Sub repository points to upstream project2", )
def test_create_head_path(self): parent_path = os.path.join(self.upstream_root, 'org/project1') parent_repo = git.Repo(parent_path) parent_repo.create_head("refs/heads/foobar") parent_repo.create_head("refs/heads/refs/heads/foobar") work_repo = Repo(parent_path, self.workspace_root, '*****@*****.**', 'User Name', '0', '0') repo = work_repo.createRepoObject(None) self.assertIn('foobar', repo.branches) self.assertIn('refs/heads/foobar', repo.branches) self.assertNotIn('refs/heads/refs/heads/foobar', repo.branches)
def test_ensure_cloned(self): parent_path = os.path.join(self.upstream_root, 'org/project1') # Forge a repo having a submodule parent_repo = git.Repo(parent_path) parent_repo.git.submodule('add', os.path.join( self.upstream_root, 'org/project2'), 'subdir') parent_repo.index.commit('Adding project2 as a submodule in subdir') # git 1.7.8 changed .git from being a directory to a file pointing # to the parent repository /.git/modules/* self.assertTrue(os.path.exists( os.path.join(parent_path, 'subdir', '.git')), msg='.git file in submodule should be a file') work_repo = Repo(parent_path, self.workspace_root, '*****@*****.**', 'User Name', '0', '0') self.assertTrue( os.path.isdir(os.path.join(self.workspace_root, 'subdir')), msg='Cloned repository has a submodule placeholder directory') self.assertFalse(os.path.exists( os.path.join(self.workspace_root, 'subdir', '.git')), msg='Submodule is not initialized') sub_repo = Repo( os.path.join(self.upstream_root, 'org/project2'), os.path.join(self.workspace_root, 'subdir'), '*****@*****.**', 'User Name', '0', '0') self.assertTrue(os.path.exists( os.path.join(self.workspace_root, 'subdir', '.git')), msg='Cloned over the submodule placeholder') self.assertEqual( os.path.join(self.upstream_root, 'org/project1'), work_repo.createRepoObject(None).remotes[0].url, message="Parent clone still point to upstream project1") self.assertEqual( os.path.join(self.upstream_root, 'org/project2'), sub_repo.createRepoObject(None).remotes[0].url, message="Sub repository points to upstream project2")
def test_ensure_cloned(self): parent_path = os.path.join(self.upstream_root, 'org/project1') # Forge a repo having a submodule parent_repo = git.Repo(parent_path) parent_repo.git.submodule('add', os.path.join( self.upstream_root, 'org/project2'), 'subdir') parent_repo.index.commit('Adding project2 as a submodule in subdir') # git 1.7.8 changed .git from being a directory to a file pointing # to the parent repository /.git/modules/* self.assertTrue(os.path.exists( os.path.join(parent_path, 'subdir', '.git')), msg='.git file in submodule should be a file') work_repo = Repo(parent_path, self.workspace_root, '*****@*****.**', 'User Name', '0', '0') self.assertTrue( os.path.isdir(os.path.join(self.workspace_root, 'subdir')), msg='Cloned repository has a submodule placeholder directory') self.assertFalse(os.path.exists( os.path.join(self.workspace_root, 'subdir', '.git')), msg='Submodule is not initialized') sub_repo = Repo( os.path.join(self.upstream_root, 'org/project2'), os.path.join(self.workspace_root, 'subdir'), '*****@*****.**', 'User Name', '0', '0') self.assertTrue(os.path.exists( os.path.join(self.workspace_root, 'subdir', '.git')), msg='Cloned over the submodule placeholder') self.assertEqual( os.path.join(self.upstream_root, 'org/project1'), work_repo.createRepoObject().remotes[0].url, message="Parent clone still point to upstream project1") self.assertEqual( os.path.join(self.upstream_root, 'org/project2'), sub_repo.createRepoObject().remotes[0].url, message="Sub repository points to upstream project2")
def test_create_head_at_char(self): """Test that we can create branches containing the '@' char. This is a regression test to make sure we are not using GitPython APIs that interpret the '@' as a special char. """ parent_path = os.path.join(self.upstream_root, 'org/project1') parent_repo = git.Repo(parent_path) parent_repo.create_head("refs/heads/foo@bar") work_repo = Repo(parent_path, self.workspace_root, '*****@*****.**', 'User Name', '0', '0') repo = work_repo.createRepoObject(None) self.assertIn('foo@bar', repo.branches)