def test_import_git_to_git_refs_changed(self): # Create a Git-to-Git CodeImport and import it incrementally with # ref and HEAD changes. self.makeTargetGitServer() job = self.getStartedJobForImport( self.makeGitCodeImport( target_rcs_type=TargetRevisionControlSystems.GIT)) code_import_id = job.code_import.id job_id = job.id self.layer.txn.commit() source_repo = GitRepo(os.path.join(self.repo_path, "source")) commit = source_repo.refs["refs/heads/master"] source_repo.refs["refs/heads/one"] = commit source_repo.refs["refs/heads/two"] = commit source_repo.refs.set_symbolic_ref("HEAD", "refs/heads/one") del source_repo.refs["refs/heads/master"] target_repo_path = os.path.join(self.target_store, job.code_import.target.unique_name) self.target_git_server.makeRepo(job.code_import.target.unique_name, [("NEWS", "contents")]) yield self.performImport(job_id) self.assertImported(code_import_id) target_repo = GitRepo(target_repo_path) self.assertContentEqual(["heads/one", "heads/two"], target_repo.refs.keys(base="refs")) self.assertEqual("ref: refs/heads/one", GitRepo(target_repo_path).refs.read_ref("HEAD"))
def test_tag(self): reva = self.simple_commit_a() r = GitRepo(".") r.refs[b"refs/tags/foo"] = reva thebranch = Branch.open('.') self.assertEqual( {"foo": default_mapping.revision_id_foreign_to_bzr(reva)}, thebranch.tags.get_tag_dict())
def start_server(self): super(GitServer, self).start_server() self.createRepository(self.repository_path) if self._use_server: repo = GitRepo(self.repository_path) self._server = TCPGitServerThread(DictBackend({"/": repo}), "localhost", 0) self._server.start()
def test_sprouted_tags(self): path, gitsha = self.make_onerev_branch() r = GitRepo(path) r.refs[b"refs/tags/lala"] = r.head() oldrepo = Repository.open(path) revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha) newbranch = self.clone_git_branch(path, "f") self.assertEqual({"lala": revid}, newbranch.tags.get_tag_dict()) self.assertEqual([revid], newbranch.repository.all_revision_ids())
def test_last_revision_info(self): reva = self.simple_commit_a() self.build_tree(['b']) r = GitRepo(".") r.stage("b") revb = r.do_commit(b"b", committer=b"Somebody <*****@*****.**>") thebranch = Branch.open('.') self.assertEqual((2, default_mapping.revision_id_foreign_to_bzr(revb)), thebranch.last_revision_info())
def makeRepo(self, tree_contents): repo = GitRepo(self.repository_path) blobs = [(Blob.from_string(contents), filename) for (filename, contents) in tree_contents] repo.object_store.add_objects(blobs) root_id = dulwich.index.commit_tree( repo.object_store, [(filename, b.id, stat.S_IFREG | 0644) for (b, filename) in blobs]) repo.do_commit(committer='Joe Foo <*****@*****.**>', message=u'<The commit message>', tree=root_id)
def test_sprouted_ghost_tags(self): path, gitsha = self.make_onerev_branch() r = GitRepo(path) self.addCleanup(r.close) r.refs[b"refs/tags/lala"] = b"aa" * 20 oldrepo = Repository.open(path) revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha) warnings, newbranch = self.callCatchWarnings(self.clone_git_branch, path, "f") self.assertEqual({}, newbranch.tags.get_tag_dict()) # Dulwich raises a UserWarning for tags with invalid target self.assertIn( ('ref refs/tags/lala points at non-present sha ' + ("aa" * 20), ), [w.args for w in warnings])
def test_interbranch_pull_with_tags(self): path, (gitsha1, gitsha2) = self.make_tworev_branch() gitrepo = GitRepo(path) gitrepo.refs[b"refs/tags/sometag"] = gitsha2 oldrepo = Repository.open(path) revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1) revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2) newbranch = self.make_branch('g') source_branch = Branch.open(path) source_branch.get_config().set_user_option("branch.fetch_tags", True) inter_branch = InterBranch.get(source_branch, newbranch) inter_branch.pull(stop_revision=revid1) self.assertEqual(revid1, newbranch.last_revision()) self.assertTrue(newbranch.repository.has_revision(revid2))
def makeRepo(self, repository_name, tree_contents): repository_path = os.path.join(self.repository_store, repository_name) os.makedirs(repository_path) self.createRepository(repository_path, bare=self._use_server) repo = GitRepo(repository_path) blobs = [ (Blob.from_string(contents), filename) for (filename, contents) in tree_contents] repo.object_store.add_objects(blobs) root_id = dulwich.index.commit_tree(repo.object_store, [ (filename, b.id, stat.S_IFREG | 0o644) for (b, filename) in blobs]) repo.do_commit(committer='Joe Foo <*****@*****.**>', message=u'<The commit message>', tree=root_id)
def test_tag_annotated(self): reva = self.simple_commit_a() o = Tag() o.name = b"foo" o.tagger = b"Jelmer <*****@*****.**>" o.message = b"add tag" o.object = (Commit, reva) o.tag_timezone = 0 o.tag_time = 42 r = GitRepo(".") r.object_store.add_object(o) r[b'refs/tags/foo'] = o.id thebranch = Branch.open('.') self.assertEqual( {"foo": default_mapping.revision_id_foreign_to_bzr(reva)}, thebranch.tags.get_tag_dict())
def test_import_git_to_git(self): # Create a Git-to-Git CodeImport and import it. self.makeTargetGitServer() job = self.getStartedJobForImport( self.makeGitCodeImport( target_rcs_type=TargetRevisionControlSystems.GIT)) code_import_id = job.code_import.id job_id = job.id self.layer.txn.commit() target_repo_path = os.path.join(self.target_store, job.code_import.target.unique_name) os.makedirs(target_repo_path) self.target_git_server.createRepository(target_repo_path, bare=True) yield self.performImport(job_id) self.assertImported(code_import_id) target_repo = GitRepo(target_repo_path) self.assertContentEqual(["heads/master"], target_repo.refs.keys(base="refs")) self.assertEqual("ref: refs/heads/master", target_repo.refs.read_ref("HEAD"))
def open_repository(self, path): full_path = os.path.normpath(os.path.join(self.root, path.lstrip("/"))) if not full_path.startswith(self.root + "/"): raise NotGitRepository("Repository %s not under store" % path) return GitRepo(full_path)