1873
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,
1876
1977
class MockTransform(object):
1878
1979
def has_named_child(self, by_parent, parent_id, name):