369
369
self.assertContainsRe(transform._limbo_name(first), 'new-1/file')
370
370
self.assertNotContainsRe(transform._limbo_name(second), 'new-1/FiLe')
372
def test_adjust_path_updates_child_limbo_names(self):
373
tree = self.make_branch_and_tree('tree')
374
transform = TreeTransform(tree)
375
self.addCleanup(transform.finalize)
376
foo_id = transform.new_directory('foo', transform.root)
377
bar_id = transform.new_directory('bar', foo_id)
378
baz_id = transform.new_directory('baz', bar_id)
379
qux_id = transform.new_directory('qux', baz_id)
380
transform.adjust_path('quxx', foo_id, bar_id)
381
self.assertStartsWith(transform._limbo_name(qux_id),
382
transform._limbo_name(bar_id))
372
384
def test_add_del(self):
373
385
start, root = self.get_transform()
374
386
start.new_directory('a', root, 'a')
1856
1868
self.assertEqual([], list(target.iter_changes(revision_tree)))
1857
1869
self.assertTrue(source.is_executable('file1-id'))
1871
def install_rot13_content_filter(self, pattern):
1872
original_registry = filters._reset_registry()
1873
def restore_registry():
1874
filters._reset_registry(original_registry)
1875
self.addCleanup(restore_registry)
1876
def rot13(chunks, context=None):
1877
return [''.join(chunks).encode('rot13')]
1878
rot13filter = filters.ContentFilter(rot13, rot13)
1879
filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
1880
os.mkdir(self.test_home_dir + '/.bazaar')
1881
rules_filename = self.test_home_dir + '/.bazaar/rules'
1882
f = open(rules_filename, 'wb')
1883
f.write('[name %s]\nrot13=yes\n' % (pattern,))
1885
def uninstall_rules():
1886
os.remove(rules_filename)
1888
self.addCleanup(uninstall_rules)
1891
def test_build_tree_content_filtered_files_are_not_hardlinked(self):
1892
"""build_tree will not hardlink files that have content filtering rules
1893
applied to them (but will still hardlink other files from the same tree
1896
self.requireFeature(HardlinkFeature)
1897
self.install_rot13_content_filter('file1')
1898
source = self.create_ab_tree()
1899
target = self.make_branch_and_tree('target')
1900
revision_tree = source.basis_tree()
1901
revision_tree.lock_read()
1902
self.addCleanup(revision_tree.unlock)
1903
build_tree(revision_tree, target, source, hardlink=True)
1905
self.addCleanup(target.unlock)
1906
self.assertEqual([], list(target.iter_changes(revision_tree)))
1907
source_stat = os.stat('source/file1')
1908
target_stat = os.stat('target/file1')
1909
self.assertNotEqual(source_stat, target_stat)
1910
source_stat = os.stat('source/file2')
1911
target_stat = os.stat('target/file2')
1912
self.assertEqualStat(source_stat, target_stat)
1859
1914
def test_case_insensitive_build_tree_inventory(self):
1860
1915
if (tests.CaseInsensitiveFilesystemFeature.available()
1861
1916
or tests.CaseInsCasePresFilenameFeature.available()):
1873
1928
self.assertEqual('FILE', target.id2path('upper-id'))
1931
class TestCommitTransform(tests.TestCaseWithTransport):
1933
def get_branch(self):
1934
tree = self.make_branch_and_tree('tree')
1936
self.addCleanup(tree.unlock)
1937
tree.commit('empty commit')
1940
def get_branch_and_transform(self):
1941
branch = self.get_branch()
1942
tt = TransformPreview(branch.basis_tree())
1943
self.addCleanup(tt.finalize)
1946
def test_commit_wrong_basis(self):
1947
branch = self.get_branch()
1948
basis = branch.repository.revision_tree(
1949
_mod_revision.NULL_REVISION)
1950
tt = TransformPreview(basis)
1951
self.addCleanup(tt.finalize)
1952
e = self.assertRaises(ValueError, tt.commit, branch, '')
1953
self.assertEqual('TreeTransform not based on branch basis: null:',
1956
def test_empy_commit(self):
1957
branch, tt = self.get_branch_and_transform()
1958
rev = tt.commit(branch, 'my message')
1959
self.assertEqual(2, branch.revno())
1960
repo = branch.repository
1961
self.assertEqual('my message', repo.get_revision(rev).message)
1963
def test_merge_parents(self):
1964
branch, tt = self.get_branch_and_transform()
1965
rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
1966
self.assertEqual(['rev1b', 'rev1c'],
1967
branch.basis_tree().get_parent_ids()[1:])
1969
def test_first_commit(self):
1970
branch = self.make_branch('branch')
1972
self.addCleanup(branch.unlock)
1973
tt = TransformPreview(branch.basis_tree())
1974
self.addCleanup(tt.finalize)
1975
tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
1976
rev = tt.commit(branch, 'my message')
1977
self.assertEqual([], branch.basis_tree().get_parent_ids())
1978
self.assertNotEqual(_mod_revision.NULL_REVISION,
1979
branch.last_revision())
1981
def test_first_commit_with_merge_parents(self):
1982
branch = self.make_branch('branch')
1984
self.addCleanup(branch.unlock)
1985
tt = TransformPreview(branch.basis_tree())
1986
self.addCleanup(tt.finalize)
1987
e = self.assertRaises(ValueError, tt.commit, branch,
1988
'my message', ['rev1b-id'])
1989
self.assertEqual('Cannot supply merge parents for first commit.',
1991
self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
1993
def test_add_files(self):
1994
branch, tt = self.get_branch_and_transform()
1995
tt.new_file('file', tt.root, 'contents', 'file-id')
1996
trans_id = tt.new_directory('dir', tt.root, 'dir-id')
1997
if SymlinkFeature.available():
1998
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
1999
rev = tt.commit(branch, 'message')
2000
tree = branch.basis_tree()
2001
self.assertEqual('file', tree.id2path('file-id'))
2002
self.assertEqual('contents', tree.get_file_text('file-id'))
2003
self.assertEqual('dir', tree.id2path('dir-id'))
2004
if SymlinkFeature.available():
2005
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2006
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2008
def test_add_unversioned(self):
2009
branch, tt = self.get_branch_and_transform()
2010
tt.new_file('file', tt.root, 'contents')
2011
self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
2012
'message', strict=True)
2014
def test_modify_strict(self):
2015
branch, tt = self.get_branch_and_transform()
2016
tt.new_file('file', tt.root, 'contents', 'file-id')
2017
tt.commit(branch, 'message', strict=True)
2018
tt = TransformPreview(branch.basis_tree())
2019
self.addCleanup(tt.finalize)
2020
trans_id = tt.trans_id_file_id('file-id')
2021
tt.delete_contents(trans_id)
2022
tt.create_file('contents', trans_id)
2023
tt.commit(branch, 'message', strict=True)
2025
def test_commit_malformed(self):
2026
"""Committing a malformed transform should raise an exception.
2028
In this case, we are adding a file without adding its parent.
2030
branch, tt = self.get_branch_and_transform()
2031
parent_id = tt.trans_id_file_id('parent-id')
2032
tt.new_file('file', parent_id, 'contents', 'file-id')
2033
self.assertRaises(errors.MalformedTransform, tt.commit, branch,
1876
2037
class MockTransform(object):
1878
2039
def has_named_child(self, by_parent, parent_id, name):
2172
2334
self.assertEqual(os.stat(limbo_path).st_mtime,
2173
2335
preview_tree.get_file_mtime('file-id'))
2337
def test_get_file_mtime_renamed(self):
2338
work_tree = self.make_branch_and_tree('tree')
2339
self.build_tree(['tree/file'])
2340
work_tree.add('file', 'file-id')
2341
preview = TransformPreview(work_tree)
2342
self.addCleanup(preview.finalize)
2343
file_trans_id = preview.trans_id_tree_file_id('file-id')
2344
preview.adjust_path('renamed', preview.root, file_trans_id)
2345
preview_tree = preview.get_preview_tree()
2346
preview_mtime = preview_tree.get_file_mtime('file-id', 'renamed')
2347
work_mtime = work_tree.get_file_mtime('file-id', 'file')
2175
2349
def test_get_file(self):
2176
2350
preview = self.get_empty_preview()
2177
2351
preview.new_file('file', preview.root, 'contents', 'file-id')