/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.12.12 by Aaron Bentley
Implement shelf creator
1
# Copyright (C) 2008 Aaron Bentley <aaron@aaronbentley.com>
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.12.19 by Aaron Bentley
Add support for writing shelves
19
from bzrlib import pack, tests, transform
20
from bzrlib.plugins.shelf2 import prepare_shelf, serialize_transform
0.12.12 by Aaron Bentley
Implement shelf creator
21
22
23
class TestPrepareShelf(tests.TestCaseWithTransport):
24
25
    def test_shelve_rename(self):
26
        tree = self.make_branch_and_tree('.')
27
        self.build_tree(['foo'])
28
        tree.add(['foo'], ['foo-id'])
29
        tree.commit('foo')
30
        tree.rename_one('foo', 'bar')
0.14.1 by Aaron Bentley
Use explicit target in ShelfCreator
31
        creator = prepare_shelf.ShelfCreator(tree, tree.basis_tree())
0.12.12 by Aaron Bentley
Implement shelf creator
32
        self.addCleanup(creator.finalize)
33
        self.assertEqual([('rename', 'foo-id', 'foo', 'bar')], list(creator))
34
        creator.shelve_rename('foo-id')
35
        work_trans_id = creator.work_transform.trans_id_file_id('foo-id')
36
        self.assertEqual('foo', creator.work_transform.final_name(
37
                         work_trans_id))
38
        shelf_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
39
        self.assertEqual('bar', creator.shelf_transform.final_name(
40
                         shelf_trans_id))
41
42
    def test_shelve_move(self):
43
        tree = self.make_branch_and_tree('.')
44
        self.build_tree(['foo/', 'bar/', 'foo/baz'])
45
        tree.add(['foo', 'bar', 'foo/baz'], ['foo-id', 'bar-id', 'baz-id'])
46
        tree.commit('foo')
47
        tree.rename_one('foo/baz', 'bar/baz')
0.14.1 by Aaron Bentley
Use explicit target in ShelfCreator
48
        creator = prepare_shelf.ShelfCreator(tree, tree.basis_tree())
0.12.12 by Aaron Bentley
Implement shelf creator
49
        self.addCleanup(creator.finalize)
50
        self.assertEqual([('rename', 'baz-id', 'foo/baz', 'bar/baz')],
51
                         list(creator))
52
        creator.shelve_rename('baz-id')
53
        work_trans_id = creator.work_transform.trans_id_file_id('baz-id')
54
        work_foo = creator.work_transform.trans_id_file_id('foo-id')
55
        self.assertEqual(work_foo, creator.work_transform.final_parent(
56
                         work_trans_id))
57
        shelf_trans_id = creator.shelf_transform.trans_id_file_id('baz-id')
58
        shelf_bar = creator.shelf_transform.trans_id_file_id('bar-id')
59
        self.assertEqual(shelf_bar, creator.shelf_transform.final_parent(
60
                         shelf_trans_id))
0.12.13 by Aaron Bentley
Implement shelving content
61
        creator.transform()
62
        self.assertEqual('foo/baz', tree.id2path('baz-id'))
63
0.12.14 by Aaron Bentley
Add shelving of created files
64
    def assertShelvedFileEqual(self, expected_content, creator, file_id):
65
        s_trans_id = creator.shelf_transform.trans_id_file_id(file_id)
66
        shelf_file = creator.shelf_transform._limbo_name(s_trans_id)
67
        self.assertFileEqual(expected_content, shelf_file)
68
0.12.13 by Aaron Bentley
Implement shelving content
69
    def test_shelve_content_change(self):
70
        tree = self.make_branch_and_tree('.')
71
        tree.lock_write()
72
        self.addCleanup(tree.unlock)
73
        self.build_tree_contents([('foo', 'a\n')])
74
        tree.add('foo', 'foo-id')
75
        tree.commit('Committed foo')
76
        self.build_tree_contents([('foo', 'b\na\nc\n')])
0.14.1 by Aaron Bentley
Use explicit target in ShelfCreator
77
        creator = prepare_shelf.ShelfCreator(tree, tree.basis_tree())
0.12.13 by Aaron Bentley
Implement shelving content
78
        self.addCleanup(creator.finalize)
79
        self.assertEqual([('modify text', 'foo-id')], list(creator))
80
        creator.shelve_text('foo-id', 'a\nc\n')
81
        creator.transform()
82
        self.assertFileEqual('a\nc\n', 'foo')
0.12.14 by Aaron Bentley
Add shelving of created files
83
        self.assertShelvedFileEqual('b\na\n', creator, 'foo-id')
84
85
    def test_shelve_creation(self):
86
        tree = self.make_branch_and_tree('.')
87
        tree.lock_write()
88
        self.addCleanup(tree.unlock)
89
        tree.commit('Empty tree')
0.12.16 by Aaron Bentley
Handle shelving directory creation
90
        self.build_tree_contents([('foo', 'a\n'), ('bar/',)])
91
        tree.add(['foo', 'bar'], ['foo-id', 'bar-id'])
0.14.1 by Aaron Bentley
Use explicit target in ShelfCreator
92
        creator = prepare_shelf.ShelfCreator(tree, tree.basis_tree())
0.12.14 by Aaron Bentley
Add shelving of created files
93
        self.addCleanup(creator.finalize)
0.12.16 by Aaron Bentley
Handle shelving directory creation
94
        self.assertEqual([('add file', 'bar-id', 'directory'),
95
                          ('add file', 'foo-id', 'file')],
96
                          sorted(list(creator)))
0.14.2 by Aaron Bentley
Somewhat clean up shelving
97
        creator.shelve_creation('foo-id')
98
        creator.shelve_creation('bar-id')
0.12.14 by Aaron Bentley
Add shelving of created files
99
        creator.transform()
0.12.15 by Aaron Bentley
Handle file-id when shelving creation
100
        self.assertRaises(StopIteration,
101
                          tree.iter_entries_by_dir(['foo-id']).next)
102
        s_trans_id = creator.shelf_transform.trans_id_file_id('foo-id')
103
        self.assertEqual('foo-id',
104
                         creator.shelf_transform.final_file_id(s_trans_id))
0.12.14 by Aaron Bentley
Add shelving of created files
105
        self.failIfExists('foo')
0.12.16 by Aaron Bentley
Handle shelving directory creation
106
        self.failIfExists('bar')
0.12.14 by Aaron Bentley
Add shelving of created files
107
        self.assertShelvedFileEqual('a\n', creator, 'foo-id')
0.12.16 by Aaron Bentley
Handle shelving directory creation
108
        s_bar_trans_id = creator.shelf_transform.trans_id_file_id('bar-id')
109
        self.assertEqual('directory',
110
            creator.shelf_transform.final_kind(s_bar_trans_id))
0.12.17 by Aaron Bentley
Handle creating symlinks
111
112
    def test_shelve_symlink_creation(self):
113
        self.requireFeature(tests.SymlinkFeature)
114
        tree = self.make_branch_and_tree('.')
115
        tree.lock_write()
116
        self.addCleanup(tree.unlock)
117
        tree.commit('Empty tree')
118
        os.symlink('bar', 'foo')
119
        tree.add('foo', 'foo-id')
0.14.1 by Aaron Bentley
Use explicit target in ShelfCreator
120
        creator = prepare_shelf.ShelfCreator(tree, tree.basis_tree())
0.12.17 by Aaron Bentley
Handle creating symlinks
121
        self.addCleanup(creator.finalize)
122
        self.assertEqual([('add file', 'foo-id', 'symlink')], 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
130
    def test_write_shelf(self):
131
        tree = self.make_branch_and_tree('tree')
132
        self.build_tree(['tree/foo'])
133
        tree.add('foo', 'foo-id')
0.14.1 by Aaron Bentley
Use explicit target in ShelfCreator
134
        creator = prepare_shelf.ShelfCreator(tree, tree.basis_tree())
0.12.19 by Aaron Bentley
Add support for writing shelves
135
        list(creator)
0.14.2 by Aaron Bentley
Somewhat clean up shelving
136
        creator.shelve_creation('foo-id')
0.12.19 by Aaron Bentley
Add support for writing shelves
137
        filename = creator.write_shelf()
138
        self.assertContainsRe(filename, 'tree/.shelf2/01$')
139
        self.failUnlessExists(filename)
140
        parser = pack.ContainerPushParser()
141
        shelf_file = open(filename, 'rb')
142
        try:
143
            parser.accept_bytes(shelf_file.read())
144
        finally:
145
            shelf_file.close()
146
        tt = transform.TransformPreview(tree)
147
        serialize_transform.deserialize(tt,
148
            iter(parser.read_pending_records()))
0.12.21 by Aaron Bentley
Add failing test of unshelver
149
150
151
class TestUnshelver(tests.TestCaseWithTransport):
152
153
    def test_unshelve(self):
154
        tree = self.make_branch_and_tree('tree')
155
        self.build_tree_contents([('tree/foo', 'bar')])
0.12.24 by Aaron Bentley
Get unshelve using merge codepath, not applying transform directly
156
        tree.lock_write()
157
        self.addCleanup(tree.unlock)
0.12.21 by Aaron Bentley
Add failing test of unshelver
158
        tree.add('foo', 'foo-id')
159
        creator = prepare_shelf.ShelfCreator(tree, tree.basis_tree())
160
        list(creator)
0.12.23 by Aaron Bentley
Fix up unshelve some more
161
        creator.shelve_creation('foo-id')
0.12.21 by Aaron Bentley
Add failing test of unshelver
162
        creator.transform()
163
        filename = creator.write_shelf()
164
        unshelver = prepare_shelf.Unshelver.from_tree_and_shelf(tree, filename)
165
        unshelver.unshelve()
166
        self.assertFileEqual('bar', 'tree/foo')