806
836
transform.apply()
807
837
transform, root = self.get_transform()
809
self.assertEqual([], list(transform._iter_changes()))
839
self.assertEqual([], list(transform.iter_changes()))
810
840
old = transform.trans_id_tree_file_id('id-1')
811
841
transform.unversion_file(old)
812
842
self.assertEqual([('id-1', ('old', None), False, (True, False),
813
843
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
814
(True, True))], list(transform._iter_changes()))
844
(True, True))], list(transform.iter_changes()))
815
845
transform.new_directory('new', root, 'id-1')
816
846
self.assertEqual([('id-1', ('old', 'new'), True, (True, True),
817
847
('eert_toor', 'eert_toor'), ('old', 'new'),
818
848
('file', 'directory'),
819
(True, False))], list(transform._iter_changes()))
849
(True, False))], list(transform.iter_changes()))
821
851
transform.finalize()
847
877
old = transform.trans_id_tree_path('old')
848
878
subdir = transform.trans_id_tree_file_id('subdir-id')
849
879
new = transform.trans_id_tree_path('new')
850
self.assertEqual([], list(transform._iter_changes()))
880
self.assertEqual([], list(transform.iter_changes()))
852
882
#content deletion
853
883
transform.delete_contents(old)
854
884
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
855
885
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', None),
856
(False, False))], list(transform._iter_changes()))
886
(False, False))], list(transform.iter_changes()))
859
889
transform.create_file('blah', old)
860
890
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
861
891
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
862
(False, False))], list(transform._iter_changes()))
892
(False, False))], list(transform.iter_changes()))
863
893
transform.cancel_deletion(old)
864
894
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
865
895
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
866
(False, False))], list(transform._iter_changes()))
896
(False, False))], list(transform.iter_changes()))
867
897
transform.cancel_creation(old)
869
899
# move file_id to a different file
870
self.assertEqual([], list(transform._iter_changes()))
900
self.assertEqual([], list(transform.iter_changes()))
871
901
transform.unversion_file(old)
872
902
transform.version_file('id-1', new)
873
903
transform.adjust_path('old', root, new)
874
904
self.assertEqual([('id-1', ('old', 'old'), True, (True, True),
875
905
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
876
(False, False))], list(transform._iter_changes()))
906
(False, False))], list(transform.iter_changes()))
877
907
transform.cancel_versioning(new)
878
908
transform._removed_id = set()
881
self.assertEqual([], list(transform._iter_changes()))
911
self.assertEqual([], list(transform.iter_changes()))
882
912
transform.set_executability(True, old)
883
913
self.assertEqual([('id-1', ('old', 'old'), False, (True, True),
884
914
('eert_toor', 'eert_toor'), ('old', 'old'), ('file', 'file'),
885
(False, True))], list(transform._iter_changes()))
915
(False, True))], list(transform.iter_changes()))
886
916
transform.set_executability(None, old)
889
self.assertEqual([], list(transform._iter_changes()))
919
self.assertEqual([], list(transform.iter_changes()))
890
920
transform.adjust_path('new', root, old)
891
921
transform._new_parent = {}
892
922
self.assertEqual([('id-1', ('old', 'new'), False, (True, True),
893
923
('eert_toor', 'eert_toor'), ('old', 'new'), ('file', 'file'),
894
(False, False))], list(transform._iter_changes()))
924
(False, False))], list(transform.iter_changes()))
895
925
transform._new_name = {}
897
927
# parent directory
898
self.assertEqual([], list(transform._iter_changes()))
928
self.assertEqual([], list(transform.iter_changes()))
899
929
transform.adjust_path('new', subdir, old)
900
930
transform._new_name = {}
901
931
self.assertEqual([('id-1', ('old', 'subdir/old'), False,
902
932
(True, True), ('eert_toor', 'subdir-id'), ('old', 'old'),
903
933
('file', 'file'), (False, False))],
904
list(transform._iter_changes()))
934
list(transform.iter_changes()))
905
935
transform._new_path = {}
1626
1657
self.assertEqual([], calls)
1627
1658
target.lock_read()
1628
1659
self.addCleanup(target.unlock)
1629
self.assertEqual([], list(target._iter_changes(revision_tree)))
1660
self.assertEqual([], list(target.iter_changes(revision_tree)))
1662
def test_build_tree_hardlink(self):
1663
self.requireFeature(HardlinkFeature)
1664
source = self.create_ab_tree()
1665
target = self.make_branch_and_tree('target')
1666
revision_tree = source.basis_tree()
1667
revision_tree.lock_read()
1668
self.addCleanup(revision_tree.unlock)
1669
build_tree(revision_tree, target, source, hardlink=True)
1671
self.addCleanup(target.unlock)
1672
self.assertEqual([], list(target.iter_changes(revision_tree)))
1673
source_stat = os.stat('source/file1')
1674
target_stat = os.stat('target/file1')
1675
self.assertEqual(source_stat, target_stat)
1677
# Explicitly disallowing hardlinks should prevent them.
1678
target2 = self.make_branch_and_tree('target2')
1679
build_tree(revision_tree, target2, source, hardlink=False)
1681
self.addCleanup(target2.unlock)
1682
self.assertEqual([], list(target2.iter_changes(revision_tree)))
1683
source_stat = os.stat('source/file1')
1684
target2_stat = os.stat('target2/file1')
1685
self.assertNotEqual(source_stat, target2_stat)
1631
1687
def test_build_tree_accelerator_tree_moved(self):
1632
1688
source = self.make_branch_and_tree('source')
1804
1878
parent = tt.trans_id_file_id('parent-id')
1805
1879
tt.new_file('file', parent, 'Contents')
1806
1880
resolve_conflicts(tt)
1883
class TestTransformPreview(tests.TestCaseWithTransport):
1885
def create_tree(self):
1886
tree = self.make_branch_and_tree('.')
1887
self.build_tree_contents([('a', 'content 1')])
1888
tree.add('a', 'a-id')
1889
tree.commit('rev1', rev_id='rev1')
1890
return tree.branch.repository.revision_tree('rev1')
1892
def get_empty_preview(self):
1893
repository = self.make_repository('repo')
1894
tree = repository.revision_tree(_mod_revision.NULL_REVISION)
1895
preview = TransformPreview(tree)
1896
self.addCleanup(preview.finalize)
1899
def test_transform_preview(self):
1900
revision_tree = self.create_tree()
1901
preview = TransformPreview(revision_tree)
1902
self.addCleanup(preview.finalize)
1904
def test_transform_preview_tree(self):
1905
revision_tree = self.create_tree()
1906
preview = TransformPreview(revision_tree)
1907
self.addCleanup(preview.finalize)
1908
preview.get_preview_tree()
1910
def test_transform_new_file(self):
1911
revision_tree = self.create_tree()
1912
preview = TransformPreview(revision_tree)
1913
self.addCleanup(preview.finalize)
1914
preview.new_file('file2', preview.root, 'content B\n', 'file2-id')
1915
preview_tree = preview.get_preview_tree()
1916
self.assertEqual(preview_tree.kind('file2-id'), 'file')
1918
preview_tree.get_file('file2-id').read(), 'content B\n')
1920
def test_diff_preview_tree(self):
1921
revision_tree = self.create_tree()
1922
preview = TransformPreview(revision_tree)
1923
self.addCleanup(preview.finalize)
1924
preview.new_file('file2', preview.root, 'content B\n', 'file2-id')
1925
preview_tree = preview.get_preview_tree()
1927
show_diff_trees(revision_tree, preview_tree, out)
1928
lines = out.getvalue().splitlines()
1929
self.assertEqual(lines[0], "=== added file 'file2'")
1930
# 3 lines of diff administrivia
1931
self.assertEqual(lines[4], "+content B")
1933
def test_transform_conflicts(self):
1934
revision_tree = self.create_tree()
1935
preview = TransformPreview(revision_tree)
1936
self.addCleanup(preview.finalize)
1937
preview.new_file('a', preview.root, 'content 2')
1938
resolve_conflicts(preview)
1939
trans_id = preview.trans_id_file_id('a-id')
1940
self.assertEqual('a.moved', preview.final_name(trans_id))
1942
def get_tree_and_preview_tree(self):
1943
revision_tree = self.create_tree()
1944
preview = TransformPreview(revision_tree)
1945
self.addCleanup(preview.finalize)
1946
a_trans_id = preview.trans_id_file_id('a-id')
1947
preview.delete_contents(a_trans_id)
1948
preview.create_file('b content', a_trans_id)
1949
preview_tree = preview.get_preview_tree()
1950
return revision_tree, preview_tree
1952
def test_iter_changes(self):
1953
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1954
root = revision_tree.inventory.root.file_id
1955
self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
1956
(root, root), ('a', 'a'), ('file', 'file'),
1958
list(preview_tree.iter_changes(revision_tree)))
1960
def test_wrong_tree_value_error(self):
1961
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1962
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1964
self.assertEqual('from_tree must be transform source tree.', str(e))
1966
def test_include_unchanged_value_error(self):
1967
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1968
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1969
revision_tree, include_unchanged=True)
1970
self.assertEqual('include_unchanged is not supported', str(e))
1972
def test_specific_files(self):
1973
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1974
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1975
revision_tree, specific_files=['pete'])
1976
self.assertEqual('specific_files is not supported', str(e))
1978
def test_want_unversioned_value_error(self):
1979
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1980
e = self.assertRaises(ValueError, preview_tree.iter_changes,
1981
revision_tree, want_unversioned=True)
1982
self.assertEqual('want_unversioned is not supported', str(e))
1984
def test_ignore_extra_trees_no_specific_files(self):
1985
# extra_trees is harmless without specific_files, so we'll silently
1986
# accept it, even though we won't use it.
1987
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1988
preview_tree.iter_changes(revision_tree, extra_trees=[preview_tree])
1990
def test_ignore_require_versioned_no_specific_files(self):
1991
# require_versioned is meaningless without specific_files.
1992
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1993
preview_tree.iter_changes(revision_tree, require_versioned=False)
1995
def test_ignore_pb(self):
1996
# pb could be supported, but TT.iter_changes doesn't support it.
1997
revision_tree, preview_tree = self.get_tree_and_preview_tree()
1998
preview_tree.iter_changes(revision_tree, pb=progress.DummyProgress())
2000
def test_kind(self):
2001
revision_tree = self.create_tree()
2002
preview = TransformPreview(revision_tree)
2003
self.addCleanup(preview.finalize)
2004
preview.new_file('file', preview.root, 'contents', 'file-id')
2005
preview.new_directory('directory', preview.root, 'dir-id')
2006
preview_tree = preview.get_preview_tree()
2007
self.assertEqual('file', preview_tree.kind('file-id'))
2008
self.assertEqual('directory', preview_tree.kind('dir-id'))
2010
def test_get_file_mtime(self):
2011
preview = self.get_empty_preview()
2012
file_trans_id = preview.new_file('file', preview.root, 'contents',
2014
limbo_path = preview._limbo_name(file_trans_id)
2015
preview_tree = preview.get_preview_tree()
2016
self.assertEqual(os.stat(limbo_path).st_mtime,
2017
preview_tree.get_file_mtime('file-id'))
2019
def test_get_file(self):
2020
preview = self.get_empty_preview()
2021
preview.new_file('file', preview.root, 'contents', 'file-id')
2022
preview_tree = preview.get_preview_tree()
2023
tree_file = preview_tree.get_file('file-id')
2025
self.assertEqual('contents', tree_file.read())
2029
def test_get_symlink_target(self):
2030
self.requireFeature(SymlinkFeature)
2031
preview = self.get_empty_preview()
2032
preview.new_symlink('symlink', preview.root, 'target', 'symlink-id')
2033
preview_tree = preview.get_preview_tree()
2034
self.assertEqual('target',
2035
preview_tree.get_symlink_target('symlink-id'))