def build_a_rev(self): builder = BranchBuilder(self.get_transport().clone('foo')) rev_id1 = builder.build_snapshot('A-id', None, [('add', ('', 'a-root-id', 'directory', None)), ('add', ('a', 'a-id', 'file', 'contents'))]) self.assertEqual('A-id', rev_id1) return builder
def test_get_branch(self): """get_branch returns the created branch.""" builder = BranchBuilder(self.get_transport().clone("foo")) branch = builder.get_branch() self.assertIsInstance(branch, _mod_branch.Branch) self.assertEqual(self.get_transport().clone("foo").base, branch.base) self.assertEqual((0, _mod_revision.NULL_REVISION), branch.last_revision_info())
def build_a_rev(self): builder = BranchBuilder(self.get_transport().clone('foo')) rev_id1 = builder.build_snapshot( 'A-id', None, [('add', ('', 'a-root-id', 'directory', None)), ('add', ('a', 'a-id', 'file', 'contents'))]) self.assertEqual('A-id', rev_id1) return builder
def test_build_one_commit(self): """doing build_commit causes a commit to happen.""" builder = BranchBuilder(self.get_transport().clone("foo")) rev_id = builder.build_commit() branch = builder.get_branch() self.assertEqual((1, rev_id), branch.last_revision_info()) self.assertEqual("commit 1", branch.repository.get_revision(branch.last_revision()).message)
def build_a_rev(self): builder = BranchBuilder(self.get_transport().clone("foo")) rev_id1 = builder.build_snapshot( "A-id", None, [("add", ("", "a-root-id", "directory", None)), ("add", ("a", "a-id", "file", "contents"))] ) self.assertEqual("A-id", rev_id1) return builder
def test_commit_message_default(self): builder = BranchBuilder(self.get_transport().clone('foo')) rev_id = builder.build_snapshot(None, None, [('add', (u'', None, 'directory', None))]) branch = builder.get_branch() rev = branch.repository.get_revision(rev_id) self.assertEqual(u'commit 1', rev.message)
def test_commit_message_callback(self): builder = BranchBuilder(self.get_transport().clone("foo")) rev_id = builder.build_snapshot( None, None, [("add", (u"", None, "directory", None))], message_callback=lambda x: u"Foo" ) branch = builder.get_branch() rev = branch.repository.get_revision(rev_id) self.assertEqual(u"Foo", rev.message)
def test_unversion_root_add_new_root(self): builder = BranchBuilder(self.get_transport().clone("foo")) builder.start_series() builder.build_snapshot("rev-1", None, [("add", ("", "TREE_ROOT", "directory", ""))]) builder.build_snapshot("rev-2", None, [("unversion", "TREE_ROOT"), ("add", ("", "my-root", "directory", ""))]) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree("rev-2") self.assertTreeShape([(u"", "my-root", "directory")], rev_tree)
def test_get_branch(self): """get_branch returns the created branch.""" builder = BranchBuilder(self.get_transport().clone('foo')) branch = builder.get_branch() self.assertIsInstance(branch, _mod_branch.Branch) self.assertEqual(self.get_transport().clone('foo').base, branch.base) self.assertEqual((0, _mod_revision.NULL_REVISION), branch.last_revision_info())
def test_build_commit_parent_ids(self): """build_commit() takes a parent_ids argument.""" builder = BranchBuilder(self.get_transport().clone("foo")) rev_id1 = builder.build_commit(parent_ids=["ghost"], allow_leftmost_as_ghost=True) rev_id2 = builder.build_commit(parent_ids=[]) branch = builder.get_branch() self.assertEqual((1, rev_id2), branch.last_revision_info()) self.assertEqual(["ghost"], branch.repository.get_revision(rev_id1).parent_ids)
def test_straightline_ancestry(self): """Test ancestry file when just committing.""" builder = BranchBuilder(self.get_transport()) rev_id_one = builder.build_commit() rev_id_two = builder.build_commit() branch = builder.get_branch() self.assertAncestryEqual([None, rev_id_one, rev_id_two], rev_id_two, branch) self.assertAncestryEqual([None, rev_id_one], rev_id_one, branch)
def test_build_two_commits(self): """The second commit has the right parents and message.""" builder = BranchBuilder(self.get_transport().clone("foo")) rev_id1 = builder.build_commit() rev_id2 = builder.build_commit() branch = builder.get_branch() self.assertEqual((2, rev_id2), branch.last_revision_info()) self.assertEqual("commit 2", branch.repository.get_revision(branch.last_revision()).message) self.assertEqual([rev_id1], branch.repository.get_revision(branch.last_revision()).parent_ids)
def test_build_one_commit(self): """doing build_commit causes a commit to happen.""" builder = BranchBuilder(self.get_transport().clone('foo')) rev_id = builder.build_commit() branch = builder.get_branch() self.assertEqual((1, rev_id), branch.last_revision_info()) self.assertEqual( 'commit 1', branch.repository.get_revision(branch.last_revision()).message)
def test_empty_flush(self): """A flush with no actions before it is a no-op.""" builder = BranchBuilder(self.get_transport().clone("foo")) builder.start_series() builder.build_snapshot("rev-1", None, [("add", ("", "TREE_ROOT", "directory", ""))]) builder.build_snapshot("rev-2", None, [("flush", None)]) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree("rev-2") self.assertTreeShape([(u"", "TREE_ROOT", "directory")], rev_tree)
def test_straightline_ancestry(self): """Test ancestry file when just committing.""" builder = BranchBuilder(self.get_transport()) rev_id_one = builder.build_commit() rev_id_two = builder.build_commit() branch = builder.get_branch() self.assertThat([rev_id_one, rev_id_two], MatchesAncestry(branch.repository, rev_id_two)) self.assertThat([rev_id_one], MatchesAncestry(branch.repository, rev_id_one))
def test_build_commit_parent_ids(self): """build_commit() takes a parent_ids argument.""" builder = BranchBuilder(self.get_transport().clone('foo')) rev_id1 = builder.build_commit(parent_ids=["ghost"], allow_leftmost_as_ghost=True) rev_id2 = builder.build_commit(parent_ids=[]) branch = builder.get_branch() self.assertEqual((1, rev_id2), branch.last_revision_info()) self.assertEqual(["ghost"], branch.repository.get_revision(rev_id1).parent_ids)
def test_start_finish_series(self): builder = BranchBuilder(self.get_transport().clone("foo")) builder.start_series() try: self.assertIsNot(None, builder._tree) self.assertEqual("w", builder._tree._lock_mode) self.assertTrue(builder._branch.is_locked()) finally: builder.finish_series() self.assertIs(None, builder._tree) self.assertFalse(builder._branch.is_locked())
def makeRepo(self, tree_contents): branch = Branch.open(self.repository_path) branch.get_config().set_user_option("create_signatures", "never") builder = BranchBuilder(branch=branch) actions = [('add', ('', 'tree-root', 'directory', None))] actions += [ ('add', (path, path + '-id', 'file', content)) for (path, content) in tree_contents] builder.build_snapshot( None, None, actions, committer='Joe Foo <*****@*****.**>', message=u'<The commit message>')
def test_build_two_commits(self): """The second commit has the right parents and message.""" builder = BranchBuilder(self.get_transport().clone('foo')) rev_id1 = builder.build_commit() rev_id2 = builder.build_commit() branch = builder.get_branch() self.assertEqual((2, rev_id2), branch.last_revision_info()) self.assertEqual( 'commit 2', branch.repository.get_revision(branch.last_revision()).message) self.assertEqual([rev_id1], branch.repository.get_revision( branch.last_revision()).parent_ids)
def test_kind_change(self): """It's possible to change the kind of an entry in a single snapshot with a bit of help from the 'flush' action. """ builder = BranchBuilder(self.get_transport().clone("foo")) builder.start_series() builder.build_snapshot( "A-id", None, [("add", (u"", "a-root-id", "directory", None)), ("add", (u"a", "a-id", "file", "content\n"))] ) builder.build_snapshot( "B-id", None, [("unversion", "a-id"), ("flush", None), ("add", (u"a", "a-id", "directory", None))] ) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree("B-id") self.assertTreeShape([(u"", "a-root-id", "directory"), (u"a", "a-id", "directory")], rev_tree)
def test_ghost_mainline_history(self): builder = BranchBuilder(self.get_transport().clone('foo')) builder.start_series() try: builder.build_snapshot('tip', ['ghost'], [('add', ('', 'ROOT_ID', 'directory', ''))], allow_leftmost_as_ghost=True) finally: builder.finish_series() b = builder.get_branch() b.lock_read() self.addCleanup(b.unlock) self.assertEqual( ('ghost', ), b.repository.get_graph().get_parent_map(['tip'])['tip'])
def test_ghost_mainline_history(self): builder = BranchBuilder(self.get_transport().clone("foo")) builder.start_series() try: builder.build_snapshot( "tip", ["ghost"], [("add", ("", "ROOT_ID", "directory", ""))], allow_leftmost_as_ghost=True ) finally: builder.finish_series() b = builder.get_branch() b.lock_read() self.addCleanup(b.unlock) self.assertEqual(("ghost",), b.repository.get_graph().get_parent_map(["tip"])["tip"])
def test_pivot_root(self): """It's possible (albeit awkward) to move an existing dir to the root in a single snapshot by using unversion then flush then add. """ builder = BranchBuilder(self.get_transport().clone("foo")) builder.start_series() builder.build_snapshot( "A-id", None, [("add", (u"", "orig-root", "directory", None)), ("add", (u"dir", "dir-id", "directory", None))], ) builder.build_snapshot( "B-id", None, [ ("unversion", "orig-root"), # implicitly unversions all children ("flush", None), ("add", (u"", "dir-id", "directory", None)), ], ) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree("B-id") self.assertTreeShape([(u"", "dir-id", "directory")], rev_tree)
def test_start_finish_series(self): builder = BranchBuilder(self.get_transport().clone('foo')) builder.start_series() try: self.assertIsNot(None, builder._tree) self.assertEqual('w', builder._tree._lock_mode) self.assertTrue(builder._branch.is_locked()) finally: builder.finish_series() self.assertIs(None, builder._tree) self.assertFalse(builder._branch.is_locked())
def test_kind_change(self): """It's possible to change the kind of an entry in a single snapshot with a bit of help from the 'flush' action. """ builder = BranchBuilder(self.get_transport().clone('foo')) builder.start_series() builder.build_snapshot('A-id', None, [('add', (u'', 'a-root-id', 'directory', None)), ('add', (u'a', 'a-id', 'file', 'content\n'))]) builder.build_snapshot('B-id', None, [('unversion', 'a-id'), ('flush', None), ('add', (u'a', 'a-id', 'directory', None))]) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree('B-id') self.assertTreeShape([(u'', 'a-root-id', 'directory'), (u'a', 'a-id', 'directory')], rev_tree)
def test_empty_flush(self): """A flush with no actions before it is a no-op.""" builder = BranchBuilder(self.get_transport().clone('foo')) builder.start_series() builder.build_snapshot('rev-1', None, [('add', ('', 'TREE_ROOT', 'directory', ''))]) builder.build_snapshot('rev-2', None, [('flush', None)]) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree('rev-2') self.assertTreeShape([(u'', 'TREE_ROOT', 'directory')], rev_tree)
def test_unversion_root_add_new_root(self): builder = BranchBuilder(self.get_transport().clone('foo')) builder.start_series() builder.build_snapshot('rev-1', None, [('add', ('', 'TREE_ROOT', 'directory', ''))]) builder.build_snapshot('rev-2', None, [('unversion', 'TREE_ROOT'), ('add', ('', 'my-root', 'directory', ''))]) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree('rev-2') self.assertTreeShape([(u'', 'my-root', 'directory')], rev_tree)
def test_format(self): """Making a BranchBuilder with a format option sets the branch type.""" builder = BranchBuilder(self.get_transport(), format='dirstate-tags') branch = builder.get_branch() self.assertIsInstance(branch, _mod_branch.BzrBranch6)
def test_create(self): """Test the constructor api.""" builder = BranchBuilder(self.get_transport().clone('foo'))
def test_format(self): """Making a BranchBuilder with a format option sets the branch type.""" builder = BranchBuilder(self.get_transport(), format="dirstate-tags") branch = builder.get_branch() self.assertIsInstance(branch, _mod_branch.BzrBranch6)
def test_pivot_root(self): """It's possible (albeit awkward) to move an existing dir to the root in a single snapshot by using unversion then flush then add. """ builder = BranchBuilder(self.get_transport().clone('foo')) builder.start_series() builder.build_snapshot('A-id', None, [('add', (u'', 'orig-root', 'directory', None)), ('add', (u'dir', 'dir-id', 'directory', None))]) builder.build_snapshot( 'B-id', None, [ ('unversion', 'orig-root'), # implicitly unversions all children ('flush', None), ('add', (u'', 'dir-id', 'directory', None)) ]) builder.finish_series() rev_tree = builder.get_branch().repository.revision_tree('B-id') self.assertTreeShape([(u'', 'dir-id', 'directory')], rev_tree)