~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revert.py

  • Committer: Martin Pool
  • Date: 2010-01-29 10:36:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4992.
  • Revision ID: mbp@sourcefrog.net-20100129103623-hywka5hymo5z13jw
Change url to canonical.com or wiki, plus some doc improvements in passing

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
2
2
#
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
12
12
#
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
16
16
 
 
17
import os
17
18
 
18
19
from bzrlib import merge, tests, transform, workingtree
19
20
 
29
30
        self.build_tree(['source/dir/', 'source/dir/contents'])
30
31
        source_tree.add(['dir', 'dir/contents'], ['dir-id', 'contents-id'])
31
32
        source_tree.commit('added dir')
32
 
        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(),
33
36
                          target_tree.basis_tree(), this_tree=target_tree)
34
37
        self.failUnlessExists('target/dir')
35
38
        self.failUnlessExists('target/dir/contents')
36
 
        target_tree.revert([])
 
39
        target_tree.revert()
37
40
        self.failIfExists('target/dir/contents')
38
41
        self.failIfExists('target/dir')
39
42
 
56
59
        # newly-added files should not be deleted
57
60
        tree.add('new_file')
58
61
        basis_tree = tree.branch.repository.revision_tree(tree.last_revision())
59
 
        tree.revert([])
 
62
        tree.revert()
60
63
        self.failUnlessExists('tree/new_file')
61
64
 
62
65
        # unchanged files should be deleted
63
66
        tree.add('new_file')
64
67
        tree.commit('add new_file')
65
 
        tree.revert([], old_tree=basis_tree)
 
68
        tree.revert(old_tree=basis_tree)
66
69
        self.failIfExists('tree/new_file')
67
 
        
 
70
 
68
71
        # files should be deleted if their changes came from merges
69
72
        merge_target.merge_from_branch(tree.branch)
70
73
        self.failUnlessExists('merge_target/new_file')
71
 
        merge_target.revert([])
 
74
        merge_target.revert()
72
75
        self.failIfExists('merge_target/new_file')
73
76
 
74
77
        # files should not be deleted if changed after a merge
75
78
        merge_target.merge_from_branch(tree.branch)
76
79
        self.failUnlessExists('merge_target/new_file')
77
80
        self.build_tree_contents([('merge_target/new_file', 'new_contents')])
78
 
        merge_target.revert([])
 
81
        merge_target.revert()
79
82
        self.failUnlessExists('merge_target/new_file')
80
83
 
81
84
    def tree_with_executable(self):
83
86
        tt = transform.TreeTransform(tree)
84
87
        tt.new_file('newfile', tt.root, 'helooo!', 'newfile-id', True)
85
88
        tt.apply()
86
 
        self.assertTrue(tree.is_executable('newfile-id'))
87
 
        tree.commit('added newfile')
 
89
        tree.lock_write()
 
90
        try:
 
91
            self.assertTrue(tree.is_executable('newfile-id'))
 
92
            tree.commit('added newfile')
 
93
        finally:
 
94
            tree.unlock()
88
95
        return tree
89
96
 
90
97
    def test_preserve_execute(self):
95
102
        tt.create_file('Woooorld!', newfile)
96
103
        tt.apply()
97
104
        tree = workingtree.WorkingTree.open('tree')
 
105
        tree.lock_write()
 
106
        self.addCleanup(tree.unlock)
98
107
        self.assertTrue(tree.is_executable('newfile-id'))
99
 
        transform.revert(tree, tree.basis_tree(), [], backups=True)
 
108
        transform.revert(tree, tree.basis_tree(), None, backups=True)
100
109
        self.assertEqual('helooo!', tree.get_file('newfile-id').read())
101
110
        self.assertTrue(tree.is_executable('newfile-id'))
102
111
 
106
115
        newfile = tt.trans_id_tree_file_id('newfile-id')
107
116
        tt.set_executability(False, newfile)
108
117
        tt.apply()
109
 
        transform.revert(tree, tree.basis_tree(), [])
 
118
        tree.lock_write()
 
119
        self.addCleanup(tree.unlock)
 
120
        transform.revert(tree, tree.basis_tree(), None)
110
121
        self.assertTrue(tree.is_executable('newfile-id'))
 
122
 
 
123
    def test_revert_deletes_files_from_revert(self):
 
124
        tree = self.make_branch_and_tree('.')
 
125
        self.build_tree(['file'])
 
126
        tree.add('file')
 
127
        tree.commit('added file', rev_id='rev1')
 
128
        os.unlink('file')
 
129
        tree.commit('removed file')
 
130
        self.failIfExists('file')
 
131
        tree.revert(old_tree=tree.branch.repository.revision_tree('rev1'))
 
132
        self.failUnlessExists('file')
 
133
        tree.revert()
 
134
        self.failIfExists('file')
 
135
        self.assertEqual({}, tree.merge_modified())
 
136
 
 
137
    def test_empty_deprecated(self):
 
138
        tree = self.make_branch_and_tree('.')
 
139
        self.build_tree(['file'])
 
140
        tree.add('file')
 
141
        self.callDeprecated(['Using [] to revert all files is deprecated'
 
142
            ' as of bzr 0.91.  Please use None (the default) instead.'],
 
143
            tree.revert, [])
 
144
        self.assertIs(None, tree.path2id('file'))
 
145
 
 
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')
 
154
        os.rmdir('dir')
 
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'))
 
160
 
 
161
    def test_revert_root_id_change(self):
 
162
        tree = self.make_branch_and_tree('.')
 
163
        tree.set_root_id('initial-root-id')
 
164
        self.build_tree(['file1'])
 
165
        tree.add(['file1'])
 
166
        tree.commit('first')
 
167
        tree.set_root_id('temp-root-id')
 
168
        self.assertEqual('temp-root-id', tree.get_root_id())
 
169
        tree.revert()
 
170
        self.assertEqual('initial-root-id', tree.get_root_id())