def test_shared_repos(self): self.make_repository('a', shared=True) ControlDir.create_branch_convenience('a/branch1') b = ControlDir.create_branch_convenience('a/branch2') b.create_checkout(lightweight=True, to_location='b') out, err = self.run_bzr('branches b') self.assertEqual(out, " branch1\n" "* branch2\n")
def push_branch( source_branch: Branch, url: str, vcs_type: str, overwrite=False, stop_revision=None, tag_selector=None, possible_transports: Optional[List[Transport]] = None, ) -> None: url, params = urlutils.split_segment_parameters(url) branch_name = params.get("branch") if branch_name is not None: branch_name = urlutils.unquote(branch_name) if vcs_type is None: vcs_type = source_branch.controldir.cloning_metadir() try: target = ControlDir.open(url, possible_transports=possible_transports) except NotBranchError: target = ControlDir.create(url, format=vcs_type, possible_transports=possible_transports) target.push_branch(source_branch, revision_id=stop_revision, overwrite=overwrite, name=branch_name, tag_selector=tag_selector)
def test_commit_join(self): repos_url = self.make_client('d', 'sc') self.build_tree({'sc/trunk/foo/bla': "data"}) self.client_add("sc/trunk") self.client_commit("sc", "foo") self.olddir = ControlDir.open("sc/trunk") os.mkdir("dc") self.newdir = self.olddir.sprout("dc") dc = self.get_commit_editor(repos_url) branches = dc.add_dir("branches") newdir = branches.add_dir("branches/newbranch") newdir.add_file("branches/newbranch/foob").modify() dc.close() wt = self.newdir.open_workingtree() self.build_tree({"dc/lala": "data"}) wt.add(["lala"]) wt.commit(message="init") joinedwt = ControlDir.create_standalone_workingtree("dc/newdir") joinedwt.pull(Branch.open(repos_url+"/branches/newbranch")) wt.subsume(joinedwt) wt.commit(message="doe") self.olddir.open_branch().pull(self.newdir.open_branch()) paths = self.client_log(repos_url, 4, 0)[4][0] self.assertEquals(('A', "/branches/newbranch", 2), paths["/trunk/newdir"])
def test_bad_dir(self): repos_url = self.make_svn_repository("d") dc = self.get_commit_editor(repos_url) dc.add_file("foo") dc.close() ControlDir.open(repos_url + "/foo")
def test_push_unnecessary_merge(self): from breezy.debug import debug_flags debug_flags.add("commit") debug_flags.add("fetch") repos_url = self.make_svn_repository("a") bzrwt = ControlDir.create_standalone_workingtree("c") self.build_tree({'c/registry/generic.c': b"Tour"}) bzrwt.add("registry") bzrwt.add("registry/generic.c") revid1 = bzrwt.commit("Add initial directory + file", rev_id=b"initialrevid") # Push first branch into Subversion newdir = ControlDir.open(repos_url + "/trunk") config = BranchConfig(repos_url + "/trunk", newdir.find_repository().uuid) config.set_user_option("allow_metadata_in_file_properties", "True") newbranch = newdir.import_branch(bzrwt.branch) c = ra.RemoteAccess(repos_url) self.assertTrue( c.check_path("trunk/registry/generic.c", c.get_latest_revnum()) == subvertpy.NODE_FILE) dc = self.get_commit_editor(repos_url) trunk = dc.open_dir("trunk") registry = trunk.open_dir("trunk/registry") registry.open_file("trunk/registry/generic.c").modify(b"BLA") dc.close() mapping = newdir.find_repository().get_mapping() merge_revid = newdir.find_repository().generate_revision_id( 2, u"trunk", mapping) # Merge self.build_tree({'c/registry/generic.c': b"DE"}) bzrwt.add_pending_merge(merge_revid) self.assertEquals(bzrwt.get_parent_ids()[1], merge_revid) revid2 = bzrwt.commit("Merge something", rev_id=b"mergerevid") bzr_parents = bzrwt.branch.repository.get_revision(revid2).parent_ids trunk = Branch.open(repos_url + "/trunk") self.assertRaises(AppendRevisionsOnlyViolation, trunk.pull, bzrwt.branch) trunk.set_append_revisions_only(False) trunk.pull(bzrwt.branch) self.assertEquals(tuple(bzr_parents), trunk.repository.get_revision(revid2).parent_ids) self.assertEquals((2, revid2), trunk.last_revision_info()) self.assertEquals( b'1 initialrevid\n2 mergerevid\n', self.client_get_prop(repos_url + "/trunk", SVN_PROP_BZR_REVISION_ID + "v3-trunk0", c.get_latest_revnum()))
def test_import_branch(self): repos_url = self.make_svn_repository("d") x = ControlDir.open(repos_url+"/trunk") origb = ControlDir.create_standalone_workingtree("origb") self.build_tree({'origb/twin': 'bla', 'origb/peaks': 'bloe'}) origb.add(["twin", "peaks"]) origb.commit("Message") b = x.import_branch(source=origb.branch) self.assertEquals(origb.branch.last_revision_info(), b.last_revision_info()) self.assertEquals(origb.branch.last_revision_info(), Branch.open(repos_url+"/trunk").last_revision_info())
def test_init(self): self.run_bzr("init-shared-repo a") self.run_bzr("init --format=default a/b") dir = ControlDir.open('a') self.assertIs(dir.open_repository().is_shared(), True) self.assertRaises(errors.NotBranchError, dir.open_branch) self.assertRaises(errors.NoWorkingTree, dir.open_workingtree) bdir = ControlDir.open('a/b') bdir.open_branch() self.assertRaises(errors.NoRepositoryPresent, bdir.open_repository) wt = bdir.open_workingtree()
def test_fetch_file_from_non_branch(self): repos_url = self.make_svn_repository('d') dc = self.get_commit_editor(repos_url) old_trunk = dc.add_dir("old-trunk") lib = old_trunk.add_dir("old-trunk/lib") lib.add_file("old-trunk/lib/file").modify(b"data") dc.close() dc = self.get_commit_editor(repos_url) trunk = dc.add_dir("trunk") lib = trunk.add_dir("trunk/lib") lib.add_file("trunk/lib/file", "old-trunk/lib/file") dc.close() oldrepos = Repository.open(repos_url) oldrepos.set_layout(TrunkLayout(0)) dir = ControlDir.create("f") newrepos = dir.create_repository() oldrepos.copy_content_into(newrepos) mapping = oldrepos.get_mapping() branch = Branch.open("%s/trunk" % repos_url) self.assertEquals(branch.mapping, mapping) self.assertEqual( (1, oldrepos.generate_revision_id(2, "trunk", mapping)), branch.last_revision_info())
def test_fetch_complex_ids_files(self): dc = self.get_commit_editor(self.repos_url) dir = dc.add_dir("dir") dir.add_file("dir/adir").modify("contents") dc.change_prop("bzr:revision-info", "") dc.change_prop("bzr:file-ids", "dir\tbloe\ndir/adir\tbla\n") dc.close() dc = self.get_commit_editor(self.repos_url) dc.add_file("bdir", "dir/adir") dir = dc.open_dir("dir") dir.delete("dir/adir") dc.change_prop("bzr:revision-info", "properties: \n") dc.change_prop("bzr:file-ids", "bdir\tbla\n") dc.close() oldrepos = Repository.open(self.repos_url) dir = ControlDir.create("f") newrepos = dir.create_repository() oldrepos.copy_content_into(newrepos) mapping = oldrepos.get_mapping() tree = newrepos.revision_tree(oldrepos.generate_revision_id(2, u"", mapping)) self.assertEquals("bloe", tree.path2id("dir")) self.assertIs(None, tree.path2id("dir/adir")) self.assertEquals("bla", tree.path2id("bdir"))
def test_mwh(self): repo = self.make_client('d', 'sc') def mv(*mvs): for a, b in mvs: self.client_copy(a, b) self.client_delete(a) self.client_commit('sc', '.') self.client_update('sc') self.build_tree({'sc/de/foo':'data', 'sc/de/bar':'DATA'}) self.client_add('sc/de') self.client_commit('sc', 'blah') #1 self.client_update('sc') os.mkdir('sc/de/trunk') self.client_add('sc/de/trunk') mv(('sc/de/foo', 'sc/de/trunk/foo'), ('sc/de/bar', 'sc/de/trunk/bar')) #2 mv(('sc/de', 'sc/pyd')) #3 self.client_delete('sc/pyd/trunk/foo') self.client_commit('sc', '.') #4 self.client_update('sc') self.make_checkout(repo + '/pyd/trunk', 'pyd') self.assertEqual("DATA", open('pyd/bar').read()) olddir = ControlDir.open("pyd") os.mkdir('bc') newdir = olddir.sprout("bc") newdir.open_branch().pull(olddir.open_branch()) wt = newdir.open_workingtree() self.assertEqual("DATA", open('bc/bar').read()) open('bc/bar', 'w').write('data') wt.commit(message="Commit from Bzr") olddir.open_branch().pull(newdir.open_branch()) self.client_update('pyd') self.assertEqual("data", open('pyd/bar').read())
def test_post_pull_bound_branch(self): # pulling to a bound branch should pass in the master branch to the # hook, allowing the correct number of emails to be sent, while still # allowing hooks that want to modify the target to do so to both # instances. target = self.make_to_branch('target') local = self.make_from_branch('local') try: local.bind(target) except errors.UpgradeRequired: # We can't bind this format to itself- typically it is the local # branch that doesn't support binding. As of May 2007 # remotebranches can't be bound. Let's instead make a new local # branch of the default type, which does allow binding. # See https://bugs.launchpad.net/bzr/+bug/112020 local = ControlDir.create_branch_convenience('local2') local.bind(target) source = self.make_from_branch('source') Branch.hooks.install_named_hook('post_pull', self.capture_post_pull_hook, None) local.pull(source) # with nothing there we should still get a notification, and # have both branches locked at the notification time. self.assertEqual([ ('post_pull', source, local.base, target.base, 0, NULL_REVISION, 0, NULL_REVISION, True, True, True) ], self.hook_calls)
def test_copy_contents_into(self): repos_url = self.make_client('d', 'dc') self.build_tree({'dc/foo/bla': b"data"}) self.client_add("dc/foo") self.client_commit("dc", "My Message") self.build_tree({ 'dc/foo/blo': b"data2", "dc/bar/foo": b"data3", 'dc/foo/bla': b"data" }) self.client_add("dc/foo/blo") self.client_add("dc/bar") self.client_commit("dc", "Second Message") repository = Repository.open(repos_url) repository.set_layout(RootLayout()) mapping = repository.get_mapping() to_controldir = ControlDir.create("e") to_repos = to_controldir.create_repository() repository.copy_content_into( to_repos, repository.generate_revision_id(2, "", mapping)) self.assertTrue( repository.has_revision( repository.generate_revision_id(2, "", mapping))) self.assertTrue( repository.has_revision( repository.generate_revision_id(1, "", mapping)))
def setup_tree(self): wt = ControlDir.create_standalone_workingtree('.') a = wt.commit("base A", allow_pointless=True) b = wt.commit("base B", allow_pointless=True) c = wt.commit("base C", allow_pointless=True) return wt, [a, b, c]
def test_simplecopy(self): repos_url = self.make_svn_repository('d') dc = self.get_commit_editor(repos_url) dc.add_file("foo").modify(b"data") dc.add_file("blie").modify(b"bloe") dc.close() dc = self.get_commit_editor(repos_url) dc.add_file("bar", "foo", 1).modify(b"data2") dc.close() controldir = ControlDir.open(repos_url) repository = controldir.find_repository() mapping = repository.get_mapping() tree1 = repository.revision_tree( repository.generate_revision_id(1, u"", mapping)) tree2 = repository.revision_tree( repository.generate_revision_id(2, u"", mapping)) self.assertNotEqual(tree1.path2id("foo"), tree2.path2id("bar")) self.assertNotEqual(tree1.path2id("foo"), tree2.path2id("blie")) self.assertIs(None, tree1.path2id("bar")) self.assertNotEqual(None, tree1.path2id("blie"))
def setup_tree(self): wt = ControlDir.create_standalone_workingtree('.') wt.commit("base A", allow_pointless=True, rev_id=b'A') wt.commit("base B", allow_pointless=True, rev_id=b'B') wt.commit("base C", allow_pointless=True, rev_id=b'C') return wt
def test_fetch_dir_upgrade(self): repos_url = self.make_client('d', 'sc') sc = self.get_commit_editor(repos_url) trunk = sc.add_dir("trunk") mylib = trunk.add_dir("trunk/mylib") mylib.add_file("trunk/mylib/bla").modify() sc.add_dir("branches") sc.close() sc = self.get_commit_editor(repos_url) branches = sc.open_dir("branches") branches.add_dir("branches/abranch", "trunk/mylib") sc.close() self.client_update('sc') olddir = ControlDir.open("sc/branches/abranch") os.mkdir("dc") newdir = olddir.sprout('dc') self.assertEqual( olddir.open_branch().last_revision(), newdir.open_branch().last_revision())
def test_create_branch_nested(self): repos_url = self.make_svn_repository("d") x = ControlDir.open(repos_url + "/trunk") b = x.create_branch() self.assertEquals(repos_url + "/trunk", b.base) transport = SvnRaTransport(repos_url) self.assertEquals(subvertpy.NODE_DIR, transport.check_path("trunk", 1))
def test_copy_branch(self): repos_url = self.make_svn_repository('d') dc = self.get_commit_editor(repos_url) trunk = dc.add_dir("trunk") dir = trunk.add_dir("trunk/dir") dir.add_file("trunk/dir/file").modify(b"data") dc.add_dir("branches") dc.close() dc = self.get_commit_editor(repos_url) branches = dc.open_dir("branches") branches.add_dir("branches/mybranch", "trunk", 1) dc.close() controldir = ControlDir.open(repos_url + "/branches/mybranch") repository = controldir.find_repository() mapping = repository.get_mapping() tree1 = repository.revision_tree( repository.generate_revision_id(1, u"trunk", mapping)) tree2 = repository.revision_tree( repository.generate_revision_id(2, u"branches/mybranch", mapping)) self.assertEqual(tree1.path2id("dir"), tree2.path2id("dir")) self.assertEqual(tree1.path2id("dir/file"), tree2.path2id("dir/file")) rm_provider = repository._revmeta_provider fileid, revid, child_create_revid = repository.get_fileid_map( rm_provider.get_revision(u"branches/mybranch", 2), mapping).as_dict()["dir/file"] self.assertEqual(fileid, tree1.path2id("dir/file")) self.assertEqual(repository.generate_revision_id(1, u"trunk", mapping), revid)
def test_make_repository_quiet(self): out, err = self.run_bzr("init-shared-repository a -q") self.assertEqual(out, "") self.assertEqual(err, "") dir = ControlDir.open('a') self.assertIs(dir.open_repository().is_shared(), True) self.assertRaises(errors.NotBranchError, dir.open_branch) self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
def test_notification_on_branch_from_repository(self): out, err = self.run_bzr("init-shared-repository -q a") self.assertEqual(out, "") self.assertEqual(err, "") dir = ControlDir.open('a') dir.open_repository() # there is a repository there e = self.assertRaises(errors.NotBranchError, dir.open_branch) self.assertContainsRe(str(e), "location is a repository")
def test_svn_import_format(self): svn_url = self.make_repository('d') self.run_bzr('svn-import --format 1.9-rich-root %s dc' % svn_url) cd = ControlDir.open('dc') self.assertEquals( cd.open_repository()._format, format_registry.make_controldir('1.9-rich-root').repository_format)
def test_list_branches_trunk(self): repos_url = self.make_svn_repository("d") x = ControlDir.open(repos_url) x.open_repository().store_layout(TrunkLayout()) b1 = x.create_branch("foo") b2 = x.create_branch("bar") self.assertEquals(set([b1.base, b2.base]), set([b.base for b in x.list_branches()]))
def test_init_repo_existing_dir(self): """Make repo in existing directory. (Malone #38331) """ out, err = self.run_bzr("init-shared-repository .") dir = ControlDir.open('.') self.assertTrue(dir.open_repository())
def test_create_branch_top_already_branch(self): repos_url = self.make_svn_repository("d") dc = self.get_commit_editor(repos_url) dc.add_file("bla").modify("contents") dc.close() x = ControlDir.open(repos_url) self.assertRaises(AlreadyBranchError, x.create_branch)
def test_shared_import_rootlayout_empty(self): dir = ControlDir.create("e") dir.create_repository(shared=True) convert_repository(Repository.open(self.repos_url), "e", RootLayout(), create_shared_repo=True)
def test_format(self): """ Test repository format is correct """ self.make_checkout(self.repos_url, 'ac') controldir = ControlDir.open("ac") self.assertRaises(NotImplementedError, controldir._format.get_format_string) self.assertEqual(controldir._format.get_format_description(), "Subversion Local Checkout")
def test_branch(self): self.run_bzr("init-shared-repo a") self.run_bzr("init --format=default a/b") self.run_bzr('branch a/b a/c') cdir = ControlDir.open('a/c') cdir.open_branch() self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository) cdir.open_workingtree()
def test_open_repos_nonroot(self): repos_url = self.make_svn_repository("d") dc = self.get_commit_editor(repos_url) dc.add_dir("trunk") dc.close() x = ControlDir.open(repos_url + "/trunk") self.assertRaises(NoRepositoryPresent, x.open_repository)
def commit_tree(self, tree, revision_id=None): tree.commit("This is a message", rev_id=revision_id) tempdir = osutils.mkdtemp( prefix='testbzrsvn-', suffix='.tmp', dir=self.test_dir) self.addCleanup(shutil.rmtree, tempdir) to_branch = ControlDir.create_branch_and_repo( os.path.join(tempdir, 'branch')) tree.branch.push(to_branch) return to_branch.basis_tree()
def run(self, from_location, to_location=None): from breezy.controldir import ControlDir if to_location is None: to_location = os.path.basename(from_location.rstrip("/\\")) from_dir = ControlDir.open(from_location) try: to_dir = ControlDir.open(to_location) except errors.NotBranchError: to_dir = ControlDir.create(to_location) try: to_repo = to_dir.open_repository() except errors.NoRepositoryPresent: to_repo = to_dir.create_repository() try: to_branch = to_dir.open_branch() except errors.NotBranchError: to_branch = to_dir.create_branch() to_branch.pull(from_dir.open_branch())