137
136
transform.finalize()
138
137
transform.finalize()
140
def test_create_files_same_timestamp(self):
141
transform, root = self.get_transform()
142
self.wt.lock_tree_write()
143
self.addCleanup(self.wt.unlock)
144
# Roll back the clock, so that we know everything is being set to the
146
transform._creation_mtime = creation_mtime = time.time() - 20.0
147
transform.create_file('content-one',
148
transform.create_path('one', root))
149
time.sleep(1) # *ugly*
150
transform.create_file('content-two',
151
transform.create_path('two', root))
153
fo, st1 = self.wt.get_file_with_stat(None, path='one', filtered=False)
155
fo, st2 = self.wt.get_file_with_stat(None, path='two', filtered=False)
157
# We only guarantee 2s resolution
158
self.assertTrue(abs(creation_mtime - st1.st_mtime) < 2.0,
159
"%s != %s within 2 seconds" % (creation_mtime, st1.st_mtime))
160
# But if we have more than that, all files should get the same result
161
self.assertEqual(st1.st_mtime, st2.st_mtime)
163
def test_change_root_id(self):
164
transform, root = self.get_transform()
165
self.assertNotEqual('new-root-id', self.wt.get_root_id())
166
transform.new_directory('', ROOT_PARENT, 'new-root-id')
167
transform.delete_contents(root)
168
transform.unversion_file(root)
169
transform.fixup_new_roots()
171
self.assertEqual('new-root-id', self.wt.get_root_id())
173
def test_change_root_id_add_files(self):
174
transform, root = self.get_transform()
175
self.assertNotEqual('new-root-id', self.wt.get_root_id())
176
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
177
transform.new_file('file', new_trans_id, ['new-contents\n'],
179
transform.delete_contents(root)
180
transform.unversion_file(root)
181
transform.fixup_new_roots()
183
self.assertEqual('new-root-id', self.wt.get_root_id())
184
self.assertEqual('new-file-id', self.wt.path2id('file'))
185
self.assertFileEqual('new-contents\n', self.wt.abspath('file'))
187
def test_add_two_roots(self):
188
transform, root = self.get_transform()
189
new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
190
new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
191
self.assertRaises(ValueError, transform.fixup_new_roots)
193
139
def test_hardlink(self):
194
140
self.requireFeature(HardlinkFeature)
195
141
transform, root = self.get_transform()
423
369
self.assertContainsRe(transform._limbo_name(first), 'new-1/file')
424
370
self.assertNotContainsRe(transform._limbo_name(second), 'new-1/FiLe')
426
def test_adjust_path_updates_child_limbo_names(self):
427
tree = self.make_branch_and_tree('tree')
428
transform = TreeTransform(tree)
429
self.addCleanup(transform.finalize)
430
foo_id = transform.new_directory('foo', transform.root)
431
bar_id = transform.new_directory('bar', foo_id)
432
baz_id = transform.new_directory('baz', bar_id)
433
qux_id = transform.new_directory('qux', baz_id)
434
transform.adjust_path('quxx', foo_id, bar_id)
435
self.assertStartsWith(transform._limbo_name(qux_id),
436
transform._limbo_name(bar_id))
438
372
def test_add_del(self):
439
373
start, root = self.get_transform()
440
374
start.new_directory('a', root, 'a')
591
525
resolve_conflicts(replace)
594
def _test_symlinks(self, link_name1,link_target1,
595
link_name2, link_target2):
597
def ozpath(p): return 'oz/' + p
528
def test_symlinks(self):
599
529
self.requireFeature(SymlinkFeature)
600
transform, root = self.get_transform()
530
transform,root = self.get_transform()
601
531
oz_id = transform.new_directory('oz', root, 'oz-id')
602
wizard = transform.new_symlink(link_name1, oz_id, link_target1,
532
wizard = transform.new_symlink('wizard', oz_id, 'wizard-target',
604
wiz_id = transform.create_path(link_name2, oz_id)
605
transform.create_symlink(link_target2, wiz_id)
534
wiz_id = transform.create_path('wizard2', oz_id)
535
transform.create_symlink('behind_curtain', wiz_id)
606
536
transform.version_file('wiz-id2', wiz_id)
607
537
transform.set_executability(True, wiz_id)
608
538
self.assertEqual(transform.find_conflicts(),
609
539
[('non-file executability', wiz_id)])
610
540
transform.set_executability(None, wiz_id)
611
541
transform.apply()
612
self.assertEqual(self.wt.path2id(ozpath(link_name1)), 'wizard-id')
613
self.assertEqual('symlink',
614
file_kind(self.wt.abspath(ozpath(link_name1))))
615
self.assertEqual(link_target2,
616
osutils.readlink(self.wt.abspath(ozpath(link_name2))))
617
self.assertEqual(link_target1,
618
osutils.readlink(self.wt.abspath(ozpath(link_name1))))
620
def test_symlinks(self):
621
self._test_symlinks('wizard', 'wizard-target',
622
'wizard2', 'behind_curtain')
624
def test_symlinks_unicode(self):
625
self.requireFeature(tests.UnicodeFilenameFeature)
626
self._test_symlinks(u'\N{Euro Sign}wizard',
627
u'wizard-targ\N{Euro Sign}t',
628
u'\N{Euro Sign}wizard2',
629
u'b\N{Euro Sign}hind_curtain')
542
self.assertEqual(self.wt.path2id('oz/wizard'), 'wizard-id')
543
self.assertEqual(file_kind(self.wt.abspath('oz/wizard')), 'symlink')
544
self.assertEqual(os.readlink(self.wt.abspath('oz/wizard2')),
546
self.assertEqual(os.readlink(self.wt.abspath('oz/wizard')),
631
549
def test_unable_create_symlink(self):
1922
1840
self.assertEqual([], list(target.iter_changes(revision_tree)))
1923
1841
self.assertTrue(source.is_executable('file1-id'))
1925
def install_rot13_content_filter(self, pattern):
1927
# self.addCleanup(filters._reset_registry, filters._reset_registry())
1928
# below, but that looks a bit... hard to read even if it's exactly
1930
original_registry = filters._reset_registry()
1931
def restore_registry():
1932
filters._reset_registry(original_registry)
1933
self.addCleanup(restore_registry)
1934
def rot13(chunks, context=None):
1935
return [''.join(chunks).encode('rot13')]
1936
rot13filter = filters.ContentFilter(rot13, rot13)
1937
filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
1938
os.mkdir(self.test_home_dir + '/.bazaar')
1939
rules_filename = self.test_home_dir + '/.bazaar/rules'
1940
f = open(rules_filename, 'wb')
1941
f.write('[name %s]\nrot13=yes\n' % (pattern,))
1943
def uninstall_rules():
1944
os.remove(rules_filename)
1946
self.addCleanup(uninstall_rules)
1949
def test_build_tree_content_filtered_files_are_not_hardlinked(self):
1950
"""build_tree will not hardlink files that have content filtering rules
1951
applied to them (but will still hardlink other files from the same tree
1954
self.requireFeature(HardlinkFeature)
1955
self.install_rot13_content_filter('file1')
1956
source = self.create_ab_tree()
1957
target = self.make_branch_and_tree('target')
1958
revision_tree = source.basis_tree()
1959
revision_tree.lock_read()
1960
self.addCleanup(revision_tree.unlock)
1961
build_tree(revision_tree, target, source, hardlink=True)
1963
self.addCleanup(target.unlock)
1964
self.assertEqual([], list(target.iter_changes(revision_tree)))
1965
source_stat = os.stat('source/file1')
1966
target_stat = os.stat('target/file1')
1967
self.assertNotEqual(source_stat, target_stat)
1968
source_stat = os.stat('source/file2')
1969
target_stat = os.stat('target/file2')
1970
self.assertEqualStat(source_stat, target_stat)
1972
1843
def test_case_insensitive_build_tree_inventory(self):
1973
if (tests.CaseInsensitiveFilesystemFeature.available()
1974
or tests.CaseInsCasePresFilenameFeature.available()):
1975
raise tests.UnavailableFeature('Fully case sensitive filesystem')
1976
1844
source = self.make_branch_and_tree('source')
1977
1845
self.build_tree(['source/file', 'source/FILE'])
1978
1846
source.add(['file', 'FILE'], ['lower-id', 'upper-id'])
1986
1854
self.assertEqual('FILE', target.id2path('upper-id'))
1989
class TestCommitTransform(tests.TestCaseWithTransport):
1991
def get_branch(self):
1992
tree = self.make_branch_and_tree('tree')
1994
self.addCleanup(tree.unlock)
1995
tree.commit('empty commit')
1998
def get_branch_and_transform(self):
1999
branch = self.get_branch()
2000
tt = TransformPreview(branch.basis_tree())
2001
self.addCleanup(tt.finalize)
2004
def test_commit_wrong_basis(self):
2005
branch = self.get_branch()
2006
basis = branch.repository.revision_tree(
2007
_mod_revision.NULL_REVISION)
2008
tt = TransformPreview(basis)
2009
self.addCleanup(tt.finalize)
2010
e = self.assertRaises(ValueError, tt.commit, branch, '')
2011
self.assertEqual('TreeTransform not based on branch basis: null:',
2014
def test_empy_commit(self):
2015
branch, tt = self.get_branch_and_transform()
2016
rev = tt.commit(branch, 'my message')
2017
self.assertEqual(2, branch.revno())
2018
repo = branch.repository
2019
self.assertEqual('my message', repo.get_revision(rev).message)
2021
def test_merge_parents(self):
2022
branch, tt = self.get_branch_and_transform()
2023
rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
2024
self.assertEqual(['rev1b', 'rev1c'],
2025
branch.basis_tree().get_parent_ids()[1:])
2027
def test_first_commit(self):
2028
branch = self.make_branch('branch')
2030
self.addCleanup(branch.unlock)
2031
tt = TransformPreview(branch.basis_tree())
2032
self.addCleanup(tt.finalize)
2033
tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
2034
rev = tt.commit(branch, 'my message')
2035
self.assertEqual([], branch.basis_tree().get_parent_ids())
2036
self.assertNotEqual(_mod_revision.NULL_REVISION,
2037
branch.last_revision())
2039
def test_first_commit_with_merge_parents(self):
2040
branch = self.make_branch('branch')
2042
self.addCleanup(branch.unlock)
2043
tt = TransformPreview(branch.basis_tree())
2044
self.addCleanup(tt.finalize)
2045
e = self.assertRaises(ValueError, tt.commit, branch,
2046
'my message', ['rev1b-id'])
2047
self.assertEqual('Cannot supply merge parents for first commit.',
2049
self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
2051
def test_add_files(self):
2052
branch, tt = self.get_branch_and_transform()
2053
tt.new_file('file', tt.root, 'contents', 'file-id')
2054
trans_id = tt.new_directory('dir', tt.root, 'dir-id')
2055
if SymlinkFeature.available():
2056
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
2057
rev = tt.commit(branch, 'message')
2058
tree = branch.basis_tree()
2059
self.assertEqual('file', tree.id2path('file-id'))
2060
self.assertEqual('contents', tree.get_file_text('file-id'))
2061
self.assertEqual('dir', tree.id2path('dir-id'))
2062
if SymlinkFeature.available():
2063
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2064
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2066
def test_add_unversioned(self):
2067
branch, tt = self.get_branch_and_transform()
2068
tt.new_file('file', tt.root, 'contents')
2069
self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
2070
'message', strict=True)
2072
def test_modify_strict(self):
2073
branch, tt = self.get_branch_and_transform()
2074
tt.new_file('file', tt.root, 'contents', 'file-id')
2075
tt.commit(branch, 'message', strict=True)
2076
tt = TransformPreview(branch.basis_tree())
2077
self.addCleanup(tt.finalize)
2078
trans_id = tt.trans_id_file_id('file-id')
2079
tt.delete_contents(trans_id)
2080
tt.create_file('contents', trans_id)
2081
tt.commit(branch, 'message', strict=True)
2083
def test_commit_malformed(self):
2084
"""Committing a malformed transform should raise an exception.
2086
In this case, we are adding a file without adding its parent.
2088
branch, tt = self.get_branch_and_transform()
2089
parent_id = tt.trans_id_file_id('parent-id')
2090
tt.new_file('file', parent_id, 'contents', 'file-id')
2091
self.assertRaises(errors.MalformedTransform, tt.commit, branch,
2095
1857
class MockTransform(object):
2097
1859
def has_named_child(self, by_parent, parent_id, name):
2392
2153
self.assertEqual(os.stat(limbo_path).st_mtime,
2393
2154
preview_tree.get_file_mtime('file-id'))
2395
def test_get_file_mtime_renamed(self):
2396
work_tree = self.make_branch_and_tree('tree')
2397
self.build_tree(['tree/file'])
2398
work_tree.add('file', 'file-id')
2399
preview = TransformPreview(work_tree)
2400
self.addCleanup(preview.finalize)
2401
file_trans_id = preview.trans_id_tree_file_id('file-id')
2402
preview.adjust_path('renamed', preview.root, file_trans_id)
2403
preview_tree = preview.get_preview_tree()
2404
preview_mtime = preview_tree.get_file_mtime('file-id', 'renamed')
2405
work_mtime = work_tree.get_file_mtime('file-id', 'file')
2407
2156
def test_get_file(self):
2408
2157
preview = self.get_empty_preview()
2409
2158
preview.new_file('file', preview.root, 'contents', 'file-id')
2832
2586
self.assertEqual(False, preview_tree.is_executable('baz-id'))
2834
def test_commit_preview_tree(self):
2835
tree = self.make_branch_and_tree('tree')
2836
rev_id = tree.commit('rev1')
2837
tree.branch.lock_write()
2838
self.addCleanup(tree.branch.unlock)
2839
tt = TransformPreview(tree)
2840
tt.new_file('file', tt.root, 'contents', 'file_id')
2841
self.addCleanup(tt.finalize)
2842
preview = tt.get_preview_tree()
2843
preview.set_parent_ids([rev_id])
2844
builder = tree.branch.get_commit_builder([rev_id])
2845
list(builder.record_iter_changes(preview, rev_id, tt.iter_changes()))
2846
builder.finish_inventory()
2847
rev2_id = builder.commit('rev2')
2848
rev2_tree = tree.branch.repository.revision_tree(rev2_id)
2849
self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
2851
def test_ascii_limbo_paths(self):
2852
self.requireFeature(tests.UnicodeFilenameFeature)
2853
branch = self.make_branch('any')
2854
tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
2855
tt = TransformPreview(tree)
2856
self.addCleanup(tt.finalize)
2857
foo_id = tt.new_directory('', ROOT_PARENT)
2858
bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
2859
limbo_path = tt._limbo_name(bar_id)
2860
self.assertEqual(limbo_path.encode('ascii', 'replace'), limbo_path)
2863
2589
class FakeSerializer(object):
2864
2590
"""Serializer implementation that simply returns the input.