/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.14.24 by Aaron Bentley
Merge with serialize-transform
1
# Copyright (C) 2008 Canonical Ltd.
0.12.12 by Aaron Bentley
Implement shelf creator
2
#
3
#    This program is free software; you can redistribute it and/or modify
4
#    it under the terms of the GNU General Public License as published by
5
#    the Free Software Foundation; either version 2 of the License, or
6
#    (at your option) any later version.
7
#
8
#    This program is distributed in the hope that it will be useful,
9
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
#    GNU General Public License for more details.
12
#
13
#    You should have received a copy of the GNU General Public License
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
16
0.12.17 by Aaron Bentley
Handle creating symlinks
17
import os
18
0.14.24 by Aaron Bentley
Merge with serialize-transform
19
from bzrlib import pack, shelf, tests, transform
0.12.12 by Aaron Bentley
Implement shelf creator
20
21
22
class TestPrepareShelf(tests.TestCaseWithTransport):
23
24
    def test_shelve_rename(self):
25
        tree = self.make_branch_and_tree('.')
26
        self.build_tree(['foo'])
27
        tree.add(['foo'], ['foo-id'])
28
        tree.commit('foo')
29
        tree.rename_one('foo', 'bar')
0.14.7 by Aaron Bentley
Misc test cleanup
30
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
0.12.12 by Aaron Bentley
Implement shelf creator
31
        self.addCleanup(creator.finalize)
32
        self.assertEqual([('rename', 'foo-id', 'foo', 'bar')], list(creator))
33
        creator.shelve_rename('foo-id')
34
        work_trans_id = creator.work_transform.trans_id_file_id('foo-id')
35
        self.assertEqual('foo', creator.work_transform.final_name(
36
                         work_trans_id))
37
        shelf_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
38
        self.assertEqual('bar', creator.shelf_transform.final_name(
39
                         shelf_trans_id))
40
41
    def test_shelve_move(self):
42
        tree = self.make_branch_and_tree('.')
43
        self.build_tree(['foo/', 'bar/', 'foo/baz'])
44
        tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
45
        tree.commit('foo')
46
        tree.rename_one('foo/baz', 'bar/baz')
0.14.7 by Aaron Bentley
Misc test cleanup
47
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
0.12.12 by Aaron Bentley
Implement shelf creator
48
        self.addCleanup(creator.finalize)
49
        self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
50
                         list(creator))
51
        creator.shelve_rename('baz-id')
52
        work_trans_id = creator.work_transform.trans_id_file_id('baz-id')
53
        work_foo = creator.work_transform.trans_id_file_id('foo-id')
54
        self.assertEqual(work_foo, creator.work_transform.final_parent(
55
                         work_trans_id))
56
        shelf_trans_id = creator.shelf_transform.trans_id_file_id('baz-id')
57
        shelf_bar = creator.shelf_transform.trans_id_file_id('bar-id')
58
        self.assertEqual(shelf_bar, creator.shelf_transform.final_parent(
59
                         shelf_trans_id))
0.12.13 by Aaron Bentley
Implement shelving content
60
        creator.transform()
61
        self.assertEqual('foo/baz', tree.id2path('baz-id'))
62
0.12.14 by Aaron Bentley
Add shelving of created files
63
    def assertShelvedFileEqual(self, expected_content, creator, file_id):
64
        s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
65
        shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
66
        self.assertFileEqual(expected_content, shelf_file)
67
0.12.13 by Aaron Bentley
Implement shelving content
68
    def test_shelve_content_change(self):
69
        tree = self.make_branch_and_tree('.')
70
        tree.lock_write()
71
        self.addCleanup(tree.unlock)
72
        self.build_tree_contents([('foo', 'a\n')])
73
        tree.add('foo', 'foo-id')
74
        tree.commit('Committed foo')
75
        self.build_tree_contents([('foo', 'b\na\nc\n')])
0.14.7 by Aaron Bentley
Misc test cleanup
76
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
0.12.13 by Aaron Bentley
Implement shelving content
77
        self.addCleanup(creator.finalize)
78
        self.assertEqual([('modify text', 'foo-id')], list(creator))
0.14.14 by Aaron Bentley
Change shelf_text to shelve_lines
79
        creator.shelve_lines('foo-id', ['a\n', 'c\n'])
0.12.13 by Aaron Bentley
Implement shelving content
80
        creator.transform()
81
        self.assertFileEqual('a\nc\n', 'foo')
0.12.14 by Aaron Bentley
Add shelving of created files
82
        self.assertShelvedFileEqual('b\na\n', creator, 'foo-id')
83
84
    def test_shelve_creation(self):
85
        tree = self.make_branch_and_tree('.')
86
        tree.lock_write()
87
        self.addCleanup(tree.unlock)
88
        tree.commit('Empty tree')
0.12.16 by Aaron Bentley
Handle shelving directory creation
89
        self.build_tree_contents([('foo', 'a\n'), ('bar/',)])
90
        tree.add(['foo', 'bar'], ['foo-id', 'bar-id'])
0.14.7 by Aaron Bentley
Misc test cleanup
91
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
0.12.14 by Aaron Bentley
Add shelving of created files
92
        self.addCleanup(creator.finalize)
0.14.13 by Aaron Bentley
Provide path and kind when deletes/adds are detected.
93
        self.assertEqual([('add file', 'bar-id', 'directory', 'bar'),
94
                          ('add file', 'foo-id', 'file', 'foo')],
0.12.16 by Aaron Bentley
Handle shelving directory creation
95
                          sorted(list(creator)))
0.14.2 by Aaron Bentley
Somewhat clean up shelving
96
        creator.shelve_creation('foo-id')
97
        creator.shelve_creation('bar-id')
0.12.14 by Aaron Bentley
Add shelving of created files
98
        creator.transform()
0.12.15 by Aaron Bentley
Handle file-id when shelving creation
99
        self.assertRaises(StopIteration,
100
                          tree.iter_entries_by_dir(['foo-id']).next)
101
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
102
        self.assertEqual('foo-id',
103
                         creator.shelf_transform.final_file_id(s_trans_id))
0.12.14 by Aaron Bentley
Add shelving of created files
104
        self.failIfExists('foo')
0.12.16 by Aaron Bentley
Handle shelving directory creation
105
        self.failIfExists('bar')
0.12.14 by Aaron Bentley
Add shelving of created files
106
        self.assertShelvedFileEqual('a\n', creator, 'foo-id')
0.12.16 by Aaron Bentley
Handle shelving directory creation
107
        s_bar_trans_id = creator.shelf_transform.trans_id_file_id('bar-id')
108
        self.assertEqual('directory',
109
            creator.shelf_transform.final_kind(s_bar_trans_id))
0.12.17 by Aaron Bentley
Handle creating symlinks
110
111
    def test_shelve_symlink_creation(self):
112
        self.requireFeature(tests.SymlinkFeature)
113
        tree = self.make_branch_and_tree('.')
114
        tree.lock_write()
115
        self.addCleanup(tree.unlock)
116
        tree.commit('Empty tree')
117
        os.symlink('bar', 'foo')
118
        tree.add('foo', 'foo-id')
0.14.7 by Aaron Bentley
Misc test cleanup
119
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
0.12.17 by Aaron Bentley
Handle creating symlinks
120
        self.addCleanup(creator.finalize)
0.14.13 by Aaron Bentley
Provide path and kind when deletes/adds are detected.
121
        self.assertEqual([('add file', 'foo-id', 'symlink', 'foo')],
122
                         list(creator))
0.14.2 by Aaron Bentley
Somewhat clean up shelving
123
        creator.shelve_creation('foo-id')
0.12.17 by Aaron Bentley
Handle creating symlinks
124
        creator.transform()
125
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
126
        self.failIfExists('foo')
127
        limbo_name = creator.shelf_transform._limbo_name(s_trans_id)
128
        self.assertEqual('bar', os.readlink(limbo_name))
0.12.19 by Aaron Bentley
Add support for writing shelves
129
0.14.12 by Aaron Bentley
Handle new dangling ids
130
    def test_shelve_creation_no_contents(self):
131
        tree = self.make_branch_and_tree('.')
132
        tree.lock_write()
133
        self.addCleanup(tree.unlock)
134
        tree.commit('Empty tree')
135
        self.build_tree(['foo'])
136
        tree.add('foo', 'foo-id')
137
        os.unlink('foo')
138
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
139
        self.addCleanup(creator.finalize)
0.14.13 by Aaron Bentley
Provide path and kind when deletes/adds are detected.
140
        self.assertEqual([('add file', 'foo-id', None, 'foo')],
0.14.12 by Aaron Bentley
Handle new dangling ids
141
                         sorted(list(creator)))
142
        creator.shelve_creation('foo-id')
143
        creator.transform()
144
        self.assertRaises(StopIteration,
145
                          tree.iter_entries_by_dir(['foo-id']).next)
146
        self.assertShelvedFileEqual('', creator, 'foo-id')
147
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
148
        self.assertEqual('foo-id',
149
                         creator.shelf_transform.final_file_id(s_trans_id))
150
        self.failIfExists('foo')
151
0.14.4 by Aaron Bentley
Implement shelving deletion
152
    def test_shelve_deletion(self):
153
        tree = self.make_branch_and_tree('tree')
0.14.11 by Aaron Bentley
Fix re-versioning
154
        tree.lock_write()
155
        self.addCleanup(tree.unlock)
0.14.4 by Aaron Bentley
Implement shelving deletion
156
        self.build_tree_contents([('tree/foo/',), ('tree/foo/bar', 'baz')])
157
        tree.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
158
        tree.commit('Added file and directory')
0.14.9 by Aaron Bentley
Shelve deleted files properly
159
        tree.unversion(['foo-id', 'bar-id'])
0.14.4 by Aaron Bentley
Implement shelving deletion
160
        os.unlink('tree/foo/bar')
161
        os.rmdir('tree/foo')
0.14.7 by Aaron Bentley
Misc test cleanup
162
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
0.14.4 by Aaron Bentley
Implement shelving deletion
163
        self.addCleanup(creator.finalize)
0.14.13 by Aaron Bentley
Provide path and kind when deletes/adds are detected.
164
        self.assertEqual([('delete file', 'bar-id', 'file', 'foo/bar'),
165
                          ('delete file', 'foo-id', 'directory', 'foo')],
0.14.4 by Aaron Bentley
Implement shelving deletion
166
                          sorted(list(creator)))
167
        creator.shelve_deletion('foo-id')
168
        creator.shelve_deletion('bar-id')
0.14.6 by Aaron Bentley
Fix deletion test
169
        creator.transform()
0.14.11 by Aaron Bentley
Fix re-versioning
170
        self.assertTrue('foo-id' in tree)
171
        self.assertTrue('bar-id' in tree)
0.14.4 by Aaron Bentley
Implement shelving deletion
172
        self.assertFileEqual('baz', 'tree/foo/bar')
173
0.14.10 by Aaron Bentley
Fix behavior with deletions, unversioning, ...
174
    def test_shelve_delete_contents(self):
175
        tree = self.make_branch_and_tree('tree')
176
        self.build_tree(['tree/foo',])
177
        tree.add('foo', 'foo-id')
178
        tree.commit('Added file and directory')
179
        os.unlink('tree/foo')
180
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
181
        self.addCleanup(creator.finalize)
0.14.13 by Aaron Bentley
Provide path and kind when deletes/adds are detected.
182
        self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
183
                         sorted(list(creator)))
0.14.10 by Aaron Bentley
Fix behavior with deletions, unversioning, ...
184
        creator.shelve_deletion('foo-id')
185
        creator.transform()
186
        self.failUnlessExists('tree/foo')
187
0.14.23 by Aaron Bentley
Allow shelving kind change
188
    def test_shelve_change_kind(self):
189
        tree = self.make_branch_and_tree('tree')
190
        self.build_tree_contents([('tree/foo', 'bar')])
191
        tree.add('foo', 'foo-id')
192
        tree.commit('Added file and directory')
193
        os.unlink('tree/foo')
194
        os.mkdir('tree/foo')
195
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
196
        self.addCleanup(creator.finalize)
197
        self.assertEqual([('change kind', 'foo-id', 'file', 'directory',
198
                           'foo')], sorted(list(creator)))
199
        creator.shelve_content_change('foo-id')
200
        creator.transform()
201
        self.assertFileEqual('bar', 'tree/foo')
202
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
203
        self.assertEqual('directory',
204
                         creator.shelf_transform._new_contents[s_trans_id])
205
0.14.10 by Aaron Bentley
Fix behavior with deletions, unversioning, ...
206
    def test_shelve_unversion(self):
207
        tree = self.make_branch_and_tree('tree')
208
        self.build_tree(['tree/foo',])
209
        tree.add('foo', 'foo-id')
210
        tree.commit('Added file and directory')
211
        tree.unversion(['foo-id'])
212
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
213
        self.addCleanup(creator.finalize)
0.14.13 by Aaron Bentley
Provide path and kind when deletes/adds are detected.
214
        self.assertEqual([('delete file', 'foo-id', 'file', 'foo')],
215
                         sorted(list(creator)))
0.14.10 by Aaron Bentley
Fix behavior with deletions, unversioning, ...
216
        creator.shelve_deletion('foo-id')
217
        creator.transform()
218
        self.failUnlessExists('tree/foo')
219
0.12.19 by Aaron Bentley
Add support for writing shelves
220
    def test_write_shelf(self):
221
        tree = self.make_branch_and_tree('tree')
222
        self.build_tree(['tree/foo'])
223
        tree.add('foo', 'foo-id')
0.14.7 by Aaron Bentley
Misc test cleanup
224
        creator = shelf.ShelfCreator(tree, tree.basis_tree())
225
        self.addCleanup(creator.finalize)
0.12.19 by Aaron Bentley
Add support for writing shelves
226
        list(creator)
0.14.2 by Aaron Bentley
Somewhat clean up shelving
227
        creator.shelve_creation('foo-id')
0.12.19 by Aaron Bentley
Add support for writing shelves
228
        filename = creator.write_shelf()
229
        self.assertContainsRe(filename, 'tree/.shelf2/01$')
230
        self.failUnlessExists(filename)
231
        parser = pack.ContainerPushParser()
232
        shelf_file = open(filename, 'rb')
233
        try:
234
            parser.accept_bytes(shelf_file.read())
235
        finally:
236
            shelf_file.close()
237
        tt = transform.TransformPreview(tree)
0.14.7 by Aaron Bentley
Misc test cleanup
238
        self.addCleanup(tt.finalize)
0.14.24 by Aaron Bentley
Merge with serialize-transform
239
        tt.deserialize(iter(parser.read_pending_records()))