1
# Copyright (C) 2006 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30
30
self.build_tree(['source/dir/', 'source/dir/contents'])
31
31
source_tree.add(['dir', 'dir/contents'], ['dir-id', 'contents-id'])
32
32
source_tree.commit('added dir')
33
merge.merge_inner(target_tree.branch, source_tree.basis_tree(),
33
target_tree.lock_write()
34
self.addCleanup(target_tree.unlock)
35
merge.merge_inner(target_tree.branch, source_tree.basis_tree(),
34
36
target_tree.basis_tree(), this_tree=target_tree)
35
self.failUnlessExists('target/dir')
36
self.failUnlessExists('target/dir/contents')
37
target_tree.revert([])
38
self.failIfExists('target/dir/contents')
39
self.failIfExists('target/dir')
37
self.assertPathExists('target/dir')
38
self.assertPathExists('target/dir/contents')
40
self.assertPathDoesNotExist('target/dir/contents')
41
self.assertPathDoesNotExist('target/dir')
41
43
def test_revert_new(self):
42
44
"""Only locally-changed new files should be preserved when reverting
57
59
# newly-added files should not be deleted
58
60
tree.add('new_file')
59
61
basis_tree = tree.branch.repository.revision_tree(tree.last_revision())
61
self.failUnlessExists('tree/new_file')
63
self.assertPathExists('tree/new_file')
63
65
# unchanged files should be deleted
64
66
tree.add('new_file')
65
67
tree.commit('add new_file')
66
tree.revert([], old_tree=basis_tree)
67
self.failIfExists('tree/new_file')
68
tree.revert(old_tree=basis_tree)
69
self.assertPathDoesNotExist('tree/new_file')
69
71
# files should be deleted if their changes came from merges
70
72
merge_target.merge_from_branch(tree.branch)
71
self.failUnlessExists('merge_target/new_file')
72
merge_target.revert([])
73
self.failIfExists('merge_target/new_file')
73
self.assertPathExists('merge_target/new_file')
75
self.assertPathDoesNotExist('merge_target/new_file')
75
77
# files should not be deleted if changed after a merge
76
78
merge_target.merge_from_branch(tree.branch)
77
self.failUnlessExists('merge_target/new_file')
79
self.assertPathExists('merge_target/new_file')
78
80
self.build_tree_contents([('merge_target/new_file', 'new_contents')])
79
merge_target.revert([])
80
self.failUnlessExists('merge_target/new_file')
82
self.assertPathExists('merge_target/new_file')
82
84
def tree_with_executable(self):
83
85
tree = self.make_branch_and_tree('tree')
84
86
tt = transform.TreeTransform(tree)
85
87
tt.new_file('newfile', tt.root, 'helooo!', 'newfile-id', True)
87
self.assertTrue(tree.is_executable('newfile-id'))
88
tree.commit('added newfile')
91
self.assertTrue(tree.is_executable('newfile-id'))
92
tree.commit('added newfile')
91
97
def test_preserve_execute(self):
96
102
tt.create_file('Woooorld!', newfile)
98
104
tree = workingtree.WorkingTree.open('tree')
106
self.addCleanup(tree.unlock)
99
107
self.assertTrue(tree.is_executable('newfile-id'))
100
transform.revert(tree, tree.basis_tree(), [], backups=True)
108
transform.revert(tree, tree.basis_tree(), None, backups=True)
101
109
self.assertEqual('helooo!', tree.get_file('newfile-id').read())
102
110
self.assertTrue(tree.is_executable('newfile-id'))
107
115
newfile = tt.trans_id_tree_file_id('newfile-id')
108
116
tt.set_executability(False, newfile)
110
transform.revert(tree, tree.basis_tree(), [])
119
self.addCleanup(tree.unlock)
120
transform.revert(tree, tree.basis_tree(), None)
111
121
self.assertTrue(tree.is_executable('newfile-id'))
113
123
def test_revert_deletes_files_from_revert(self):
117
127
tree.commit('added file', rev_id='rev1')
118
128
os.unlink('file')
119
129
tree.commit('removed file')
120
self.failIfExists('file')
121
tree.revert([], old_tree=tree.branch.repository.revision_tree('rev1'))
122
self.failUnlessExists('file')
124
self.failIfExists('file')
130
self.assertPathDoesNotExist('file')
131
tree.revert(old_tree=tree.branch.repository.revision_tree('rev1'))
132
self.assertPathExists('file')
134
self.assertPathDoesNotExist('file')
125
135
self.assertEqual({}, tree.merge_modified())
137
def test_revert_file_in_deleted_dir(self):
138
tree = self.make_branch_and_tree('.')
139
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
140
tree.add(['dir', 'dir/file1', 'dir/file2'],
141
['dir-id', 'file1-id', 'file2-id'])
142
tree.commit("Added files")
143
os.unlink('dir/file1')
144
os.unlink('dir/file2')
146
tree.remove(['dir/', 'dir/file1', 'dir/file2'])
147
tree.revert(['dir/file1'])
148
self.assertPathExists('dir/file1')
149
self.assertPathDoesNotExist('dir/file2')
150
self.assertEqual('dir-id', tree.path2id('dir'))
152
def test_revert_root_id_change(self):
153
tree = self.make_branch_and_tree('.')
154
tree.set_root_id('initial-root-id')
155
self.build_tree(['file1'])
158
tree.set_root_id('temp-root-id')
159
self.assertEqual('temp-root-id', tree.get_root_id())
161
self.assertEqual('initial-root-id', tree.get_root_id())