1804
1818
parent = tt.trans_id_file_id('parent-id')
1805
1819
tt.new_file('file', parent, 'Contents')
1806
1820
resolve_conflicts(tt)
1823
class TestTransformPreview(tests.TestCaseWithTransport):
1825
def create_tree(self):
1826
tree = self.make_branch_and_tree('.')
1827
self.build_tree_contents([('a', 'content 1')])
1828
tree.add('a', 'a-id')
1829
tree.commit('rev1', rev_id='rev1')
1830
return tree.branch.repository.revision_tree('rev1')
1832
def get_empty_preview(self):
1833
repository = self.make_repository('repo')
1834
tree = repository.revision_tree(_mod_revision.NULL_REVISION)
1835
return TransformPreview(tree)
1837
def test_transform_preview(self):
1838
revision_tree = self.create_tree()
1839
preview = TransformPreview(revision_tree)
1841
def test_transform_preview_tree(self):
1842
revision_tree = self.create_tree()
1843
preview = TransformPreview(revision_tree)
1844
preview.get_preview_tree()
1846
def test_transform_new_file(self):
1847
revision_tree = self.create_tree()
1848
preview = TransformPreview(revision_tree)
1849
preview.new_file('file2', preview.root, 'content B\n', 'file2-id')
1850
preview_tree = preview.get_preview_tree()
1851
self.assertEqual(preview_tree.kind('file2-id'), 'file')
1853
preview_tree.get_file('file2-id').read(), 'content B\n')
1855
def test_diff_preview_tree(self):
1856
revision_tree = self.create_tree()
1857
preview = TransformPreview(revision_tree)
1858
preview.new_file('file2', preview.root, 'content B\n', 'file2-id')
1859
preview_tree = preview.get_preview_tree()
1861
show_diff_trees(revision_tree, preview_tree, out)
1862
lines = out.getvalue().splitlines()
1863
self.assertEqual(lines[0], "=== added file 'file2'")
1864
# 3 lines of diff administrivia
1865
self.assertEqual(lines[4], "+content B")
1867
def test_transform_conflicts(self):
1868
revision_tree = self.create_tree()
1869
preview = TransformPreview(revision_tree)
1870
preview.new_file('a', preview.root, 'content 2')
1871
resolve_conflicts(preview)
1872
trans_id = preview.trans_id_file_id('a-id')
1873
self.assertEqual('a.moved', preview.final_name(trans_id))
1875
def get_tree_and_preview_tree(self):
1876
revision_tree = self.create_tree()
1877
preview = TransformPreview(revision_tree)
1878
a_trans_id = preview.trans_id_file_id('a-id')
1879
preview.delete_contents(a_trans_id)
1880
preview.create_file('b content', a_trans_id)
1881
preview_tree = preview.get_preview_tree()
1882
return revision_tree, preview_tree
1884
def test_iter_changes(self):
1885
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1886
root = revision_tree.inventory.root.file_id
1887
self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
1888
(root, root), ('a', 'a'), ('file', 'file'),
1890
list(preview_tree._iter_changes(revision_tree)))
1892
def test_wrong_tree_value_error(self):
1893
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1894
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1896
self.assertEqual('from_tree must be transform source tree.', str(e))
1898
def test_include_unchanged_value_error(self):
1899
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1900
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1901
revision_tree, include_unchanged=True)
1902
self.assertEqual('include_unchanged is not supported', str(e))
1904
def test_specific_files(self):
1905
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1906
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1907
revision_tree, specific_files=['pete'])
1908
self.assertEqual('specific_files is not supported', str(e))
1910
def test_want_unversioned_value_error(self):
1911
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1912
e = self.assertRaises(ValueError, preview_tree._iter_changes,
1913
revision_tree, want_unversioned=True)
1914
self.assertEqual('want_unversioned is not supported', str(e))
1916
def test_ignore_extra_trees_no_specific_files(self):
1917
# extra_trees is harmless without specific_files, so we'll silently
1918
# accept it, even though we won't use it.
1919
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1920
preview_tree._iter_changes(revision_tree, extra_trees=[preview_tree])
1922
def test_ignore_require_versioned_no_specific_files(self):
1923
# require_versioned is meaningless without specific_files.
1924
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1925
preview_tree._iter_changes(revision_tree, require_versioned=False)
1927
def test_ignore_pb(self):
1928
# pb could be supported, but TT.iter_changes doesn't support it.
1929
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1930
preview_tree._iter_changes(revision_tree, pb=progress.DummyProgress())
1932
def test_kind(self):
1933
revision_tree = self.create_tree()
1934
preview = TransformPreview(revision_tree)
1935
preview.new_file('file', preview.root, 'contents', 'file-id')
1936
preview.new_directory('directory', preview.root, 'dir-id')
1937
preview_tree = preview.get_preview_tree()
1938
self.assertEqual('file', preview_tree.kind('file-id'))
1939
self.assertEqual('directory', preview_tree.kind('dir-id'))
1941
def test_get_file_mtime(self):
1942
preview = self.get_empty_preview()
1943
file_trans_id = preview.new_file('file', preview.root, 'contents',
1945
limbo_path = preview._limbo_name(file_trans_id)
1946
preview_tree = preview.get_preview_tree()
1947
self.assertEqual(os.stat(limbo_path).st_mtime,
1948
preview_tree.get_file_mtime('file-id'))
1950
def test_get_file(self):
1951
preview = self.get_empty_preview()
1952
preview.new_file('file', preview.root, 'contents', 'file-id')
1953
preview_tree = preview.get_preview_tree()
1954
tree_file = preview_tree.get_file('file-id')
1956
self.assertEqual('contents', tree_file.read())