525
525
resolve_conflicts(replace)
528
def test_symlinks(self):
528
def _test_symlinks(self, link_name1,link_target1,
529
link_name2, link_target2):
531
def ozpath(p): return 'oz/' + p
529
533
self.requireFeature(SymlinkFeature)
530
transform,root = self.get_transform()
534
transform, root = self.get_transform()
531
535
oz_id = transform.new_directory('oz', root, 'oz-id')
532
wizard = transform.new_symlink('wizard', oz_id, 'wizard-target',
536
wizard = transform.new_symlink(link_name1, oz_id, link_target1,
534
wiz_id = transform.create_path('wizard2', oz_id)
535
transform.create_symlink('behind_curtain', wiz_id)
538
wiz_id = transform.create_path(link_name2, oz_id)
539
transform.create_symlink(link_target2, wiz_id)
536
540
transform.version_file('wiz-id2', wiz_id)
537
541
transform.set_executability(True, wiz_id)
538
542
self.assertEqual(transform.find_conflicts(),
539
543
[('non-file executability', wiz_id)])
540
544
transform.set_executability(None, wiz_id)
541
545
transform.apply()
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')),
546
self.assertEqual(self.wt.path2id(ozpath(link_name1)), 'wizard-id')
547
self.assertEqual('symlink',
548
file_kind(self.wt.abspath(ozpath(link_name1))))
549
self.assertEqual(link_target2,
550
osutils.readlink(self.wt.abspath(ozpath(link_name2))))
551
self.assertEqual(link_target1,
552
osutils.readlink(self.wt.abspath(ozpath(link_name1))))
554
def test_symlinks(self):
555
self._test_symlinks('wizard', 'wizard-target',
556
'wizard2', 'behind_curtain')
558
def test_symlinks_unicode(self):
559
self.requireFeature(tests.UnicodeFilenameFeature)
560
self._test_symlinks(u'\N{Euro Sign}wizard',
561
u'wizard-targ\N{Euro Sign}t',
562
u'\N{Euro Sign}wizard2',
563
u'b\N{Euro Sign}hind_curtain')
549
565
def test_unable_create_symlink(self):
1857
1873
self.assertEqual('FILE', target.id2path('upper-id'))
1876
class TestCommitTransform(tests.TestCaseWithTransport):
1878
def get_branch(self):
1879
tree = self.make_branch_and_tree('tree')
1881
self.addCleanup(tree.unlock)
1882
tree.commit('empty commit')
1885
def get_branch_and_transform(self):
1886
branch = self.get_branch()
1887
tt = TransformPreview(branch.basis_tree())
1888
self.addCleanup(tt.finalize)
1891
def test_commit_wrong_basis(self):
1892
branch = self.get_branch()
1893
basis = branch.repository.revision_tree(
1894
_mod_revision.NULL_REVISION)
1895
tt = TransformPreview(basis)
1896
self.addCleanup(tt.finalize)
1897
e = self.assertRaises(ValueError, tt.commit, branch, '')
1898
self.assertEqual('TreeTransform not based on branch basis: null:',
1901
def test_empy_commit(self):
1902
branch, tt = self.get_branch_and_transform()
1903
rev = tt.commit(branch, 'my message')
1904
self.assertEqual(2, branch.revno())
1905
repo = branch.repository
1906
self.assertEqual('my message', repo.get_revision(rev).message)
1908
def test_merge_parents(self):
1909
branch, tt = self.get_branch_and_transform()
1910
rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
1911
self.assertEqual(['rev1b', 'rev1c'],
1912
branch.basis_tree().get_parent_ids()[1:])
1914
def test_first_commit(self):
1915
branch = self.make_branch('branch')
1917
self.addCleanup(branch.unlock)
1918
tt = TransformPreview(branch.basis_tree())
1919
tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
1920
rev = tt.commit(branch, 'my message')
1921
self.assertEqual([], branch.basis_tree().get_parent_ids())
1922
self.assertNotEqual(_mod_revision.NULL_REVISION,
1923
branch.last_revision())
1925
def test_first_commit_with_merge_parents(self):
1926
branch = self.make_branch('branch')
1928
self.addCleanup(branch.unlock)
1929
tt = TransformPreview(branch.basis_tree())
1930
e = self.assertRaises(ValueError, tt.commit, branch,
1931
'my message', ['rev1b-id'])
1932
self.assertEqual('Cannot supply merge parents for first commit.',
1934
self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
1936
def test_add_files(self):
1937
branch, tt = self.get_branch_and_transform()
1938
tt.new_file('file', tt.root, 'contents', 'file-id')
1939
trans_id = tt.new_directory('dir', tt.root, 'dir-id')
1940
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
1941
rev = tt.commit(branch, 'message')
1942
tree = branch.basis_tree()
1943
self.assertEqual('file', tree.id2path('file-id'))
1944
self.assertEqual('contents', tree.get_file_text('file-id'))
1945
self.assertEqual('dir', tree.id2path('dir-id'))
1946
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
1947
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
1949
def test_add_unversioned(self):
1950
branch, tt = self.get_branch_and_transform()
1951
tt.new_file('file', tt.root, 'contents')
1952
self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
1953
'message', strict=True)
1955
def test_modify_strict(self):
1956
branch, tt = self.get_branch_and_transform()
1957
tt.new_file('file', tt.root, 'contents', 'file-id')
1958
tt.commit(branch, 'message', strict=True)
1959
tt = TransformPreview(branch.basis_tree())
1960
trans_id = tt.trans_id_file_id('file-id')
1961
tt.delete_contents(trans_id)
1962
tt.create_file('contents', trans_id)
1963
tt.commit(branch, 'message', strict=True)
1965
def test_commit_malformed(self):
1966
"""Committing a malformed transform should raise an exception.
1968
In this case, we are adding a file without adding its parent.
1970
branch, tt = self.get_branch_and_transform()
1971
parent_id = tt.trans_id_file_id('parent-id')
1972
tt.new_file('file', parent_id, 'contents', 'file-id')
1973
self.assertRaises(errors.MalformedTransform, tt.commit, branch,
1860
1977
class MockTransform(object):
1862
1979
def has_named_child(self, by_parent, parent_id, name):
2589
2711
self.assertEqual(False, preview_tree.is_executable('baz-id'))
2713
def test_commit_preview_tree(self):
2714
tree = self.make_branch_and_tree('tree')
2715
rev_id = tree.commit('rev1')
2716
tree.branch.lock_write()
2717
self.addCleanup(tree.branch.unlock)
2718
tt = TransformPreview(tree)
2719
tt.new_file('file', tt.root, 'contents', 'file_id')
2720
self.addCleanup(tt.finalize)
2721
preview = tt.get_preview_tree()
2722
preview.set_parent_ids([rev_id])
2723
builder = tree.branch.get_commit_builder([rev_id])
2724
list(builder.record_iter_changes(preview, rev_id, tt.iter_changes()))
2725
builder.finish_inventory()
2726
rev2_id = builder.commit('rev2')
2727
rev2_tree = tree.branch.repository.revision_tree(rev2_id)
2728
self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
2730
def test_ascii_limbo_paths(self):
2731
self.requireFeature(tests.UnicodeFilenameFeature)
2732
branch = self.make_branch('any')
2733
tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
2734
tt = TransformPreview(tree)
2735
foo_id = tt.new_directory('', ROOT_PARENT)
2736
bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
2737
limbo_path = tt._limbo_name(bar_id)
2738
self.assertEqual(limbo_path.encode('ascii', 'replace'), limbo_path)
2592
2741
class FakeSerializer(object):
2593
2742
"""Serializer implementation that simply returns the input.