/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/per_workingtree/test_add.py

  • Committer: Jelmer Vernooij
  • Date: 2018-03-24 17:48:04 UTC
  • mfrom: (6921 work)
  • mto: This revision was merged to the branch mainline in revision 6923.
  • Revision ID: jelmer@jelmer.uk-20180324174804-xf22o05byoj12x1q
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from breezy.bzr import (
24
24
    inventory,
25
25
    )
26
 
from breezy.tests.matchers import HasLayout
 
26
from breezy.tests.matchers import HasLayout, HasPathRelations
27
27
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
28
28
 
29
29
 
33
33
        """Check that the tree has the correct layout."""
34
34
        self.assertThat(tree, HasLayout(expected))
35
35
 
 
36
    def assertPathRelations(self, previous_tree, tree, relations):
 
37
        self.assertThat(tree, HasPathRelations(previous_tree, relations))
 
38
 
36
39
    def test_add_one(self):
37
40
        tree = self.make_branch_and_tree('.')
38
41
        self.build_tree(['one'])
39
42
        tree.add('one')
40
 
        root_id = tree.get_root_id()
41
43
 
42
 
        self.assertTreeLayout(
43
 
            [('', root_id), ('one', tree.path2id('one'))], tree)
 
44
        self.assertTreeLayout(['', 'one'], tree)
44
45
 
45
46
    def test_add_existing_id(self):
46
47
        """Adding an entry with a pre-existing id raises DuplicateFileId"""
51
52
        tree.add(['a'])
52
53
        self.assertRaises(errors.DuplicateFileId,
53
54
                          tree.add, ['b'], [tree.path2id('a')])
54
 
        root_id = tree.get_root_id()
55
55
        # And the entry should not have been added.
56
 
        self.assertTreeLayout([('', root_id), ('a', tree.path2id('a'))], tree)
 
56
        self.assertTreeLayout(['', 'a'], tree)
57
57
 
58
58
    def test_add_old_id(self):
59
59
        """We can add an old id, as long as it doesn't exist now."""
64
64
        tree.add(['a'])
65
65
        file_id = tree.path2id('a')
66
66
        tree.commit('first')
67
 
        root_id = tree.get_root_id()
68
67
        # And the entry should not have been added.
69
68
        tree.unversion(['a'])
70
69
        tree.add(['b'], [file_id])
71
 
        self.assertTreeLayout([('', root_id), ('b', file_id)], tree)
72
 
        self.assertTreeLayout([('', root_id), ('a', file_id)],
73
 
                              tree.basis_tree())
 
70
        self.assertPathRelations(
 
71
                tree.basis_tree(), tree,
 
72
                [('', ''), ('b', 'a')])
74
73
 
75
74
    def test_add_one_list(self):
76
75
        tree = self.make_branch_and_tree('.')
77
76
        self.build_tree(['one'])
78
77
        tree.add(['one'])
79
 
        root_id = tree.get_root_id()
80
78
 
81
 
        self.assertTreeLayout(
82
 
            [('', root_id), ('one', tree.path2id('one'))], tree)
 
79
        self.assertTreeLayout(['', 'one'], tree)
83
80
 
84
81
    def test_add_one_new_id(self):
85
82
        tree = self.make_branch_and_tree('.')
86
83
        self.build_tree(['one'])
87
84
        tree.add(['one'])
88
 
        root_id = tree.get_root_id()
89
 
        one_id = tree.path2id('one')
90
85
 
91
 
        self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
 
86
        self.assertTreeLayout(['', 'one'], tree)
92
87
 
93
88
    def test_add_unicode(self):
94
89
        tree = self.make_branch_and_tree('.')
97
92
        except UnicodeError:
98
93
            raise tests.TestSkipped('Filesystem does not support filename.')
99
94
        tree.add([u'f\xf6'])
100
 
        root_id = tree.get_root_id()
101
 
        foo_id = tree.path2id(u'f\xf6')
102
95
 
103
 
        self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
 
96
        self.assertTreeLayout(['', u'f\xf6'], tree)
104
97
 
105
98
    def test_add_subdir_with_ids(self):
106
99
        tree = self.make_branch_and_tree('.')
122
115
        tree.add(['dir'])
123
116
        tree.add(['dir/subdir'])
124
117
        tree.add(['dir/subdir/foo'])
125
 
        root_id = tree.get_root_id()
126
118
 
127
 
        self.assertTreeLayout([
128
 
            ('', root_id),
129
 
            ('dir/', tree.path2id('dir')),
130
 
            ('dir/subdir/', tree.path2id('dir/subdir')),
131
 
            ('dir/subdir/foo', tree.path2id('dir/subdir/foo'))],
132
 
            tree)
 
119
        self.assertTreeLayout(
 
120
            ['', 'dir/', 'dir/subdir/', 'dir/subdir/foo'], tree)
133
121
 
134
122
    def test_add_multiple(self):
135
123
        tree = self.make_branch_and_tree('.')
136
124
        self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
137
125
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'])
138
 
        root_id = tree.get_root_id()
139
126
 
140
 
        self.assertTreeLayout([
141
 
            (p, tree.path2id(p))
142
 
            for p in ['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo']],
 
127
        self.assertTreeLayout(
 
128
            ['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'],
143
129
            tree)
144
130
 
145
131
    def test_add_multiple_with_file_ids(self):
149
135
        self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
150
136
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
151
137
                 ['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
152
 
        root_id = tree.get_root_id()
153
138
 
154
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
139
        self.assertTreeLayout([('', tree.get_root_id()), ('a', 'a-id'), ('b', 'b-id'),
155
140
                               ('dir/', 'dir-id'), ('dir/subdir/', 'subdir-id'),
156
141
                               ('dir/subdir/foo', 'foo-id')], tree)
157
142
 
158
143
    def test_add_invalid(self):
159
144
        tree = self.make_branch_and_tree('.')
 
145
        if not tree._format.supports_versioned_directories:
 
146
            raise tests.TestNotApplicable(
 
147
                'format does not support versioned directories')
160
148
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
161
 
        root_id = tree.get_root_id()
162
149
 
163
150
        self.assertRaises(errors.NotVersionedError,
164
151
                          tree.add, ['dir/subdir'])
165
 
        self.assertTreeLayout([('', root_id)], tree)
 
152
        self.assertTreeLayout([''], tree)
166
153
 
167
154
    def test_add_after_remove(self):
168
155
        tree = self.make_branch_and_tree('.')
 
156
        if not tree._format.supports_versioned_directories:
 
157
            raise tests.TestNotApplicable(
 
158
                'format does not support versioned directories')
169
159
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
170
 
        root_id = tree.get_root_id()
171
160
        tree.add(['dir'])
172
161
        tree.commit('dir')
173
162
        tree.unversion(['dir'])
174
163
        self.assertRaises(errors.NotVersionedError,
175
 
                          tree.add, ['dir/subdir'])
 
164
                          tree.add, ['dir/subdir/foo'])
176
165
 
177
166
    def test_add_root(self):
178
167
        # adding the root should be a no-op, or at least not
179
168
        # do anything whacky.
180
169
        tree = self.make_branch_and_tree('.')
181
 
        tree.lock_write()
182
 
        tree.add('')
183
 
        self.assertEqual([''], list(tree.all_versioned_paths()))
184
 
        # the root should have been changed to be a new unique root.
185
 
        self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
186
 
        tree.unlock()
 
170
        with tree.lock_write():
 
171
            tree.add('')
 
172
            self.assertEqual([''], list(tree.all_versioned_paths()))
 
173
            # the root should have been changed to be a new unique root.
 
174
            if tree._format.supports_setting_file_ids:
 
175
                self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
187
176
 
188
177
    def test_add_previously_added(self):
189
178
        # adding a path that was previously added should work