1337
1337
tree.commit('old tree')
1338
1338
tree.lock_read()
1339
1339
self.addCleanup(tree.unlock)
1340
basis_tree = tree.basis_tree()
1341
basis_tree.lock_read()
1342
self.addCleanup(basis_tree.unlock)
1340
1343
diff_obj = DiffFromTool(['python', '-c',
1341
1344
'print "@old_path @new_path"'],
1345
basis_tree, tree, output)
1343
1346
diff_obj._prepare_files('file-id', 'file', 'file')
1344
self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
1345
self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\file')
1347
# The old content should be readonly
1348
self.assertReadableByAttrib(diff_obj._root, 'old\\file',
1350
# The new content should use the tree object, not a 'new' file anymore
1351
self.assertEndsWith(tree.basedir, 'work/tree')
1352
self.assertReadableByAttrib(tree.basedir, 'file', r'work\\tree\\file$')
1347
1354
def assertReadableByAttrib(self, cwd, relpath, regex):
1348
1355
proc = subprocess.Popen(['attrib', relpath],
1349
1356
stdout=subprocess.PIPE,
1352
result = proc.stdout.read()
1353
self.assertContainsRe(result, regex)
1358
(result, err) = proc.communicate()
1359
self.assertContainsRe(result.replace('\r\n', '\n'), regex)
1355
1361
def test_prepare_files(self):
1356
1362
output = StringIO()
1379
1385
self.assertContainsRe(old_path, 'old/oldname$')
1380
1386
self.assertEqual(0, os.stat(old_path).st_mtime)
1381
self.assertContainsRe(new_path, 'new/newname$')
1387
self.assertContainsRe(new_path, 'tree/newname$')
1382
1388
self.assertFileEqual('oldcontent', old_path)
1383
1389
self.assertFileEqual('newcontent', new_path)
1384
1390
if osutils.host_os_dereferences_symlinks():