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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
18
from bzrlib import merge, tests, transform, workingtree
30
29
self.build_tree(['source/dir/', 'source/dir/contents'])
31
30
source_tree.add(['dir', 'dir/contents'], ['dir-id', 'contents-id'])
32
31
source_tree.commit('added dir')
33
target_tree.lock_write()
34
self.addCleanup(target_tree.unlock)
35
merge.merge_inner(target_tree.branch, source_tree.basis_tree(),
32
merge.merge_inner(target_tree.branch, source_tree.basis_tree(),
36
33
target_tree.basis_tree(), this_tree=target_tree)
37
34
self.failUnlessExists('target/dir')
38
35
self.failUnlessExists('target/dir/contents')
36
target_tree.revert([])
40
37
self.failIfExists('target/dir/contents')
41
38
self.failIfExists('target/dir')
59
56
# newly-added files should not be deleted
60
57
tree.add('new_file')
61
58
basis_tree = tree.branch.repository.revision_tree(tree.last_revision())
63
60
self.failUnlessExists('tree/new_file')
65
62
# unchanged files should be deleted
66
63
tree.add('new_file')
67
64
tree.commit('add new_file')
68
tree.revert(old_tree=basis_tree)
65
tree.revert([], old_tree=basis_tree)
69
66
self.failIfExists('tree/new_file')
71
68
# files should be deleted if their changes came from merges
72
69
merge_target.merge_from_branch(tree.branch)
73
70
self.failUnlessExists('merge_target/new_file')
71
merge_target.revert([])
75
72
self.failIfExists('merge_target/new_file')
77
74
# files should not be deleted if changed after a merge
78
75
merge_target.merge_from_branch(tree.branch)
79
76
self.failUnlessExists('merge_target/new_file')
80
77
self.build_tree_contents([('merge_target/new_file', 'new_contents')])
78
merge_target.revert([])
82
79
self.failUnlessExists('merge_target/new_file')
84
81
def tree_with_executable(self):
86
83
tt = transform.TreeTransform(tree)
87
84
tt.new_file('newfile', tt.root, 'helooo!', 'newfile-id', True)
91
self.assertTrue(tree.is_executable('newfile-id'))
92
tree.commit('added newfile')
86
self.assertTrue(tree.is_executable('newfile-id'))
87
tree.commit('added newfile')
97
90
def test_preserve_execute(self):
102
95
tt.create_file('Woooorld!', newfile)
104
97
tree = workingtree.WorkingTree.open('tree')
106
self.addCleanup(tree.unlock)
107
98
self.assertTrue(tree.is_executable('newfile-id'))
108
transform.revert(tree, tree.basis_tree(), None, backups=True)
99
transform.revert(tree, tree.basis_tree(), [], backups=True)
109
100
self.assertEqual('helooo!', tree.get_file('newfile-id').read())
110
101
self.assertTrue(tree.is_executable('newfile-id'))
115
106
newfile = tt.trans_id_tree_file_id('newfile-id')
116
107
tt.set_executability(False, newfile)
119
self.addCleanup(tree.unlock)
120
transform.revert(tree, tree.basis_tree(), None)
109
transform.revert(tree, tree.basis_tree(), [])
121
110
self.assertTrue(tree.is_executable('newfile-id'))
123
def test_revert_deletes_files_from_revert(self):
124
tree = self.make_branch_and_tree('.')
125
self.build_tree(['file'])
127
tree.commit('added file', rev_id='rev1')
129
tree.commit('removed file')
130
self.failIfExists('file')
131
tree.revert(old_tree=tree.branch.repository.revision_tree('rev1'))
132
self.failUnlessExists('file')
134
self.failIfExists('file')
135
self.assertEqual({}, tree.merge_modified())
137
def test_empty_deprecated(self):
138
tree = self.make_branch_and_tree('.')
139
self.build_tree(['file'])
141
self.callDeprecated(['Using [] to revert all files is deprecated'
142
' as of bzr 0.91. Please use None (the default) instead.'],
144
self.assertIs(None, tree.path2id('file'))
146
def test_revert_file_in_deleted_dir(self):
147
tree = self.make_branch_and_tree('.')
148
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
149
tree.add(['dir', 'dir/file1', 'dir/file2'],
150
['dir-id', 'file1-id', 'file2-id'])
151
tree.commit("Added files")
152
os.unlink('dir/file1')
153
os.unlink('dir/file2')
155
tree.remove(['dir/', 'dir/file1', 'dir/file2'])
156
tree.revert(['dir/file1'])
157
self.failUnlessExists('dir/file1')
158
self.failIfExists('dir/file2')
159
self.assertEqual('dir-id', tree.path2id('dir'))