972
972
Please see bzrlib.treebuilder for more details.
977
PreviewTrees are based on TreeTransforms. This means they can represent
978
virtually any state that a WorkingTree can have, including unversioned files.
979
They can be used to test the output of anything that produces TreeTransforms,
980
such as merge algorithms and revert. They can also be used to test anything
981
that takes arbitrary Trees as its input.
985
# Get an empty tree to base the transform on.
986
b = self.make_branch('.')
987
empty_tree = b.repository.revision_tree(_mod_revision.NULL_REVISION)
988
tt = TransformPreview(empty_tree)
989
self.addCleanup(tt.finalize)
990
# Empty trees don't have a root, so add it first.
991
root = tt.new_directory('', ROOT_PARENT, 'tree-root')
992
# Set the contents of a file.
993
tt.new_file('new-file', root, 'contents', 'file-id')
994
preview = tt.get_preview_tree()
996
self.assertEqual('contents', preview.get_file_text('file-id'))
998
PreviewTrees can stack, with each tree falling back to the previous::
1000
tt2 = TransformPreview(preview)
1001
self.addCleanup(tt2.finalize)
1002
tt2.new_file('new-file2', tt2.root, 'contents2', 'file-id2')
1003
preview2 = tt2.get_preview_tree()
1004
self.assertEqual('contents', preview2.get_file_text('file-id'))
1005
self.assertEqual('contents2', preview2.get_file_text('file-id2'))
975
1008
Temporarily changing state
976
1009
~~~~~~~~~~~~~~~~~~~~~~~~~~