/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_revert.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        """Reverting a merge that adds a directory deletes the directory"""
27
27
        source_tree = self.make_branch_and_tree('source')
28
28
        source_tree.commit('empty tree')
29
 
        target_tree = source_tree.controldir.sprout(
30
 
            'target').open_workingtree()
 
29
        target_tree = source_tree.bzrdir.sprout('target').open_workingtree()
31
30
        self.build_tree(['source/dir/', 'source/dir/contents'])
32
 
        source_tree.add(['dir', 'dir/contents'], [b'dir-id', b'contents-id'])
 
31
        source_tree.add(['dir', 'dir/contents'], ['dir-id', 'contents-id'])
33
32
        source_tree.commit('added dir')
34
33
        target_tree.lock_write()
35
34
        self.addCleanup(target_tree.unlock)
54
53
        """
55
54
        tree = self.make_branch_and_tree('tree')
56
55
        tree.commit('empty tree')
57
 
        merge_target = tree.controldir.sprout(
58
 
            'merge_target').open_workingtree()
 
56
        merge_target = tree.bzrdir.sprout('merge_target').open_workingtree()
59
57
        self.build_tree(['tree/new_file'])
60
58
 
61
59
        # newly-added files should not be deleted
79
77
        # files should not be deleted if changed after a merge
80
78
        merge_target.merge_from_branch(tree.branch)
81
79
        self.assertPathExists('merge_target/new_file')
82
 
        self.build_tree_contents([('merge_target/new_file', b'new_contents')])
 
80
        self.build_tree_contents([('merge_target/new_file', 'new_contents')])
83
81
        merge_target.revert()
84
82
        self.assertPathExists('merge_target/new_file')
85
83
 
86
84
    def tree_with_executable(self):
87
85
        tree = self.make_branch_and_tree('tree')
88
 
        tt = tree.transform()
89
 
        tt.new_file('newfile', tt.root, [b'helooo!'], b'newfile-id', True)
 
86
        tt = transform.TreeTransform(tree)
 
87
        tt.new_file('newfile', tt.root, 'helooo!', 'newfile-id', True)
90
88
        tt.apply()
91
 
        with tree.lock_write():
92
 
            self.assertTrue(tree.is_executable('newfile'))
 
89
        tree.lock_write()
 
90
        try:
 
91
            self.assertTrue(tree.is_executable('newfile-id'))
93
92
            tree.commit('added newfile')
 
93
        finally:
 
94
            tree.unlock()
94
95
        return tree
95
96
 
96
97
    def test_preserve_execute(self):
97
98
        tree = self.tree_with_executable()
98
 
        tt = tree.transform()
99
 
        newfile = tt.trans_id_tree_path('newfile')
 
99
        tt = transform.TreeTransform(tree)
 
100
        newfile = tt.trans_id_tree_file_id('newfile-id')
100
101
        tt.delete_contents(newfile)
101
 
        tt.create_file([b'Woooorld!'], newfile)
 
102
        tt.create_file('Woooorld!', newfile)
102
103
        tt.apply()
103
104
        tree = workingtree.WorkingTree.open('tree')
104
105
        tree.lock_write()
105
106
        self.addCleanup(tree.unlock)
106
 
        self.assertTrue(tree.is_executable('newfile'))
 
107
        self.assertTrue(tree.is_executable('newfile-id'))
107
108
        transform.revert(tree, tree.basis_tree(), None, backups=True)
108
 
        with tree.get_file('newfile', 'rb') as f:
109
 
            self.assertEqual(b'helooo!', f.read())
110
 
        self.assertTrue(tree.is_executable('newfile'))
 
109
        self.assertEqual('helooo!', tree.get_file('newfile-id').read())
 
110
        self.assertTrue(tree.is_executable('newfile-id'))
111
111
 
112
112
    def test_revert_executable(self):
113
113
        tree = self.tree_with_executable()
114
 
        tt = tree.transform()
115
 
        newfile = tt.trans_id_tree_path('newfile')
 
114
        tt = transform.TreeTransform(tree)
 
115
        newfile = tt.trans_id_tree_file_id('newfile-id')
116
116
        tt.set_executability(False, newfile)
117
117
        tt.apply()
118
118
        tree.lock_write()
119
119
        self.addCleanup(tree.unlock)
120
120
        transform.revert(tree, tree.basis_tree(), None)
121
 
        self.assertTrue(tree.is_executable('newfile'))
 
121
        self.assertTrue(tree.is_executable('newfile-id'))
122
122
 
123
123
    def test_revert_deletes_files_from_revert(self):
124
124
        tree = self.make_branch_and_tree('.')
125
125
        self.build_tree(['file'])
126
126
        tree.add('file')
127
 
        rev1 = tree.commit('added file')
128
 
        with tree.lock_read():
129
 
            file_sha = tree.get_file_sha1('file')
 
127
        tree.commit('added file', rev_id='rev1')
130
128
        os.unlink('file')
131
129
        tree.commit('removed file')
132
130
        self.assertPathDoesNotExist('file')
133
 
        tree.revert(old_tree=tree.branch.repository.revision_tree(rev1))
134
 
        self.assertEqual({'file': file_sha}, tree.merge_modified())
 
131
        tree.revert(old_tree=tree.branch.repository.revision_tree('rev1'))
135
132
        self.assertPathExists('file')
136
133
        tree.revert()
137
134
        self.assertPathDoesNotExist('file')
141
138
        tree = self.make_branch_and_tree('.')
142
139
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
143
140
        tree.add(['dir', 'dir/file1', 'dir/file2'],
144
 
                 [b'dir-id', b'file1-id', b'file2-id'])
 
141
                 ['dir-id', 'file1-id', 'file2-id'])
145
142
        tree.commit("Added files")
146
143
        os.unlink('dir/file1')
147
144
        os.unlink('dir/file2')
150
147
        tree.revert(['dir/file1'])
151
148
        self.assertPathExists('dir/file1')
152
149
        self.assertPathDoesNotExist('dir/file2')
153
 
        self.assertEqual(b'dir-id', tree.path2id('dir'))
 
150
        self.assertEqual('dir-id', tree.path2id('dir'))
154
151
 
155
152
    def test_revert_root_id_change(self):
156
153
        tree = self.make_branch_and_tree('.')
157
 
        tree.set_root_id(b'initial-root-id')
 
154
        tree.set_root_id('initial-root-id')
158
155
        self.build_tree(['file1'])
159
156
        tree.add(['file1'])
160
157
        tree.commit('first')
161
 
        tree.set_root_id(b'temp-root-id')
162
 
        self.assertEqual(b'temp-root-id', tree.path2id(''))
 
158
        tree.set_root_id('temp-root-id')
 
159
        self.assertEqual('temp-root-id', tree.get_root_id())
163
160
        tree.revert()
164
 
        self.assertEqual(b'initial-root-id', tree.path2id(''))
 
161
        self.assertEqual('initial-root-id', tree.get_root_id())