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()
1922
1868
self.assertEqual([], list(target.iter_changes(revision_tree)))
1923
1869
self.assertTrue(source.is_executable('file1-id'))
1925
def install_rot13_content_filter(self, pattern):
1926
original_registry = filters._reset_registry()
1927
def restore_registry():
1928
filters._reset_registry(original_registry)
1929
self.addCleanup(restore_registry)
1930
def rot13(chunks, context=None):
1931
return [''.join(chunks).encode('rot13')]
1932
rot13filter = filters.ContentFilter(rot13, rot13)
1933
filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
1934
os.mkdir(self.test_home_dir + '/.bazaar')
1935
rules_filename = self.test_home_dir + '/.bazaar/rules'
1936
f = open(rules_filename, 'wb')
1937
f.write('[name %s]\nrot13=yes\n' % (pattern,))
1939
def uninstall_rules():
1940
os.remove(rules_filename)
1942
self.addCleanup(uninstall_rules)
1945
def test_build_tree_content_filtered_files_are_not_hardlinked(self):
1946
"""build_tree will not hardlink files that have content filtering rules
1947
applied to them (but will still hardlink other files from the same tree
1950
self.requireFeature(HardlinkFeature)
1951
self.install_rot13_content_filter('file1')
1952
source = self.create_ab_tree()
1953
target = self.make_branch_and_tree('target')
1954
revision_tree = source.basis_tree()
1955
revision_tree.lock_read()
1956
self.addCleanup(revision_tree.unlock)
1957
build_tree(revision_tree, target, source, hardlink=True)
1959
self.addCleanup(target.unlock)
1960
self.assertEqual([], list(target.iter_changes(revision_tree)))
1961
source_stat = os.stat('source/file1')
1962
target_stat = os.stat('target/file1')
1963
self.assertNotEqual(source_stat, target_stat)
1964
source_stat = os.stat('source/file2')
1965
target_stat = os.stat('target/file2')
1966
self.assertEqualStat(source_stat, target_stat)
1968
1871
def test_case_insensitive_build_tree_inventory(self):
1969
1872
if (tests.CaseInsensitiveFilesystemFeature.available()
1970
1873
or tests.CaseInsCasePresFilenameFeature.available()):
2048
1951
branch, tt = self.get_branch_and_transform()
2049
1952
tt.new_file('file', tt.root, 'contents', 'file-id')
2050
1953
trans_id = tt.new_directory('dir', tt.root, 'dir-id')
2051
if SymlinkFeature.available():
2052
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
1954
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
2053
1955
rev = tt.commit(branch, 'message')
2054
1956
tree = branch.basis_tree()
2055
1957
self.assertEqual('file', tree.id2path('file-id'))
2056
1958
self.assertEqual('contents', tree.get_file_text('file-id'))
2057
1959
self.assertEqual('dir', tree.id2path('dir-id'))
2058
if SymlinkFeature.available():
2059
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2060
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
1960
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
1961
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2062
1963
def test_add_unversioned(self):
2063
1964
branch, tt = self.get_branch_and_transform()
2553
2454
self.assertEqual(('missing', None, None, None), summary)
2555
2456
def test_file_content_summary_executable(self):
2457
if not osutils.supports_executable():
2458
raise TestNotApplicable()
2556
2459
preview = self.get_empty_preview()
2557
2460
path_id = preview.new_file('path', preview.root, 'contents', 'path-id')
2558
2461
preview.set_executability(True, path_id)
2735
2638
preview = self.get_empty_preview()
2736
2639
root = preview.new_directory('', ROOT_PARENT, 'tree-root')
2737
2640
# FIXME: new_directory should mark root.
2738
preview.fixup_new_roots()
2641
preview.adjust_path('', ROOT_PARENT, root)
2739
2642
preview_tree = preview.get_preview_tree()
2740
2643
file_trans_id = preview.new_file('a', preview.root, 'contents',