/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
16
17
"""Tests for repository commit builder."""
18
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
19
import os
2831.5.1 by Vincent Ladeuil
Portability fix in TestCommitBuilder for unlink.
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import (
5609.31.2 by mbp at sourcefrog
Also turn off whoami inference in per_repository tests
22
    config,
2831.5.1 by Vincent Ladeuil
Portability fix in TestCommitBuilder for unlink.
23
    errors,
24
    osutils,
25
    repository,
3668.5.1 by Jelmer Vernooij
Use NULL_REVISION rather than None for Repository.revision_tree().
26
    revision as _mod_revision,
2831.5.1 by Vincent Ladeuil
Portability fix in TestCommitBuilder for unlink.
27
    tests,
28
    )
7490.74.3 by Jelmer Vernooij
Fix tests.
29
from breezy.sixish import PY3
7322.1.7 by Jelmer Vernooij
Fix remaining tests.
30
from breezy.tree import TreeChange
6670.4.3 by Jelmer Vernooij
Fix more imports.
31
from breezy.bzr import (
6883.22.19 by Jelmer Vernooij
Add records_per_file_revision attribute.
32
    inventorytree,
6670.4.3 by Jelmer Vernooij
Fix more imports.
33
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
34
from breezy.tests import per_repository
35
from breezy.tests import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
36
    features,
37
    )
5010.2.24 by Vincent Ladeuil
Fix imports in per_repository/test_commit_builder.py.
38
7344.1.1 by Martin
Fix tests that need whoami not to be set
39
from ..test_bedding import override_whoami
40
5010.2.24 by Vincent Ladeuil
Fix imports in per_repository/test_commit_builder.py.
41
42
class TestCommitBuilder(per_repository.TestCaseWithRepository):
1740.3.3 by Jelmer Vernooij
Move storing directories and links to commit builder.
43
1740.3.10 by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m.
44
    def test_get_commit_builder(self):
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
45
        branch = self.make_branch('.')
46
        branch.repository.lock_write()
47
        builder = branch.repository.get_commit_builder(
6351.3.3 by Jelmer Vernooij
Convert more stuff to use config stacks.
48
            branch, [], branch.get_config_stack())
2831.5.1 by Vincent Ladeuil
Portability fix in TestCommitBuilder for unlink.
49
        self.assertIsInstance(builder, repository.CommitBuilder)
2805.6.1 by Robert Collins
Set random_revid on CommitBuilder when a commit generated its own revision id.
50
        self.assertTrue(builder.random_revid)
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
51
        branch.repository.commit_write_group()
52
        branch.repository.unlock()
1740.3.3 by Jelmer Vernooij
Move storing directories and links to commit builder.
53
3775.2.4 by Robert Collins
Start on a CommitBuilder.record_iter_changes method.
54
    def test_finish_inventory_record_iter_changes(self):
55
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
56
        with tree.lock_write():
3775.2.4 by Robert Collins
Start on a CommitBuilder.record_iter_changes method.
57
            builder = tree.branch.get_commit_builder([])
58
            try:
4183.5.4 by Robert Collins
Turn record_iter_changes into a generator to emit file system hashes.
59
                list(builder.record_iter_changes(tree, tree.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
60
                                                 tree.iter_changes(tree.basis_tree())))
3775.2.4 by Robert Collins
Start on a CommitBuilder.record_iter_changes method.
61
                builder.finish_inventory()
62
            except:
63
                builder.abort()
64
                raise
65
            repo = tree.branch.repository
66
            repo.commit_write_group()
1740.3.3 by Jelmer Vernooij
Move storing directories and links to commit builder.
67
3775.2.5 by Robert Collins
CommitBuilder.abort() is callable after record_iter_changes.
68
    def test_abort_record_iter_changes(self):
69
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
70
        with tree.lock_write():
3775.2.5 by Robert Collins
CommitBuilder.abort() is callable after record_iter_changes.
71
            builder = tree.branch.get_commit_builder([])
72
            try:
3775.2.29 by Robert Collins
Updates to the form of add_inventory_by_delta that landed in trunk.
73
                basis = tree.basis_tree()
74
                last_rev = tree.last_revision()
75
                changes = tree.iter_changes(basis)
4183.5.4 by Robert Collins
Turn record_iter_changes into a generator to emit file system hashes.
76
                list(builder.record_iter_changes(tree, last_rev, changes))
3775.2.5 by Robert Collins
CommitBuilder.abort() is callable after record_iter_changes.
77
                builder.finish_inventory()
3775.2.29 by Robert Collins
Updates to the form of add_inventory_by_delta that landed in trunk.
78
            finally:
3775.2.5 by Robert Collins
CommitBuilder.abort() is callable after record_iter_changes.
79
                builder.abort()
80
5777.6.8 by Jelmer Vernooij
Add test for get_commit_builder(lossy=True).
81
    def test_commit_lossy(self):
82
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
83
        with tree.lock_write():
5777.6.8 by Jelmer Vernooij
Add test for get_commit_builder(lossy=True).
84
            builder = tree.branch.get_commit_builder([], lossy=True)
85
            list(builder.record_iter_changes(tree, tree.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
86
                                             tree.iter_changes(tree.basis_tree())))
5777.6.8 by Jelmer Vernooij
Add test for get_commit_builder(lossy=True).
87
            builder.finish_inventory()
88
            rev_id = builder.commit('foo bar blah')
89
        rev = tree.branch.repository.get_revision(rev_id)
90
        self.assertEqual('foo bar blah', rev.message)
91
1740.3.10 by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m.
92
    def test_commit_message(self):
1740.3.7 by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder.
93
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
94
        with tree.lock_write():
2617.6.8 by Robert Collins
Review feedback and documentation.
95
            builder = tree.branch.get_commit_builder([])
5718.4.6 by Jelmer Vernooij
inline function only used once.
96
            list(builder.record_iter_changes(tree, tree.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
97
                                             tree.iter_changes(tree.basis_tree())))
5718.4.6 by Jelmer Vernooij
inline function only used once.
98
            builder.finish_inventory()
2617.6.8 by Robert Collins
Review feedback and documentation.
99
            rev_id = builder.commit('foo bar blah')
1740.3.9 by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit().
100
        rev = tree.branch.repository.get_revision(rev_id)
101
        self.assertEqual('foo bar blah', rev.message)
102
6217.5.1 by Jelmer Vernooij
Add CommitBuilder.updates_branch.
103
    def test_updates_branch(self):
104
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
105
        with tree.lock_write():
6217.5.1 by Jelmer Vernooij
Add CommitBuilder.updates_branch.
106
            builder = tree.branch.get_commit_builder([])
107
            list(builder.record_iter_changes(tree, tree.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
108
                                             tree.iter_changes(tree.basis_tree())))
6217.5.1 by Jelmer Vernooij
Add CommitBuilder.updates_branch.
109
            builder.finish_inventory()
110
            will_update_branch = builder.updates_branch
111
            rev_id = builder.commit('might update the branch')
112
        actually_updated_branch = (tree.branch.last_revision() == rev_id)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
113
        self.assertEqual(actually_updated_branch, will_update_branch)
6217.5.1 by Jelmer Vernooij
Add CommitBuilder.updates_branch.
114
3775.2.6 by Robert Collins
CommitBuilder can specify a revision_id with record_iter_changes.
115
    def test_commit_with_revision_id_record_iter_changes(self):
116
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
117
        with tree.lock_write():
3775.2.6 by Robert Collins
CommitBuilder can specify a revision_id with record_iter_changes.
118
            # use a unicode revision id to test more corner cases.
119
            # The repository layer is meant to handle this.
120
            revision_id = u'\xc8abc'.encode('utf8')
121
            try:
122
                try:
123
                    builder = tree.branch.get_commit_builder([],
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
                                                             revision_id=revision_id)
3775.2.6 by Robert Collins
CommitBuilder can specify a revision_id with record_iter_changes.
125
                except errors.NonAsciiRevisionId:
6973.13.2 by Jelmer Vernooij
Fix some more tests.
126
                    revision_id = b'abc'
3775.2.6 by Robert Collins
CommitBuilder can specify a revision_id with record_iter_changes.
127
                    builder = tree.branch.get_commit_builder([],
7143.15.2 by Jelmer Vernooij
Run autopep8.
128
                                                             revision_id=revision_id)
6747.1.1 by Jelmer Vernooij
Remove unnecessary ExcludesUnsupported exception.
129
            except repository.CannotSetRevisionId:
3775.2.6 by Robert Collins
CommitBuilder can specify a revision_id with record_iter_changes.
130
                # This format doesn't support supplied revision ids
131
                return
132
            self.assertFalse(builder.random_revid)
133
            try:
4183.5.4 by Robert Collins
Turn record_iter_changes into a generator to emit file system hashes.
134
                list(builder.record_iter_changes(tree, tree.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
135
                                                 tree.iter_changes(tree.basis_tree())))
3775.2.6 by Robert Collins
CommitBuilder can specify a revision_id with record_iter_changes.
136
                builder.finish_inventory()
137
            except:
138
                builder.abort()
139
                raise
140
            self.assertEqual(revision_id, builder.commit('foo bar'))
141
        self.assertTrue(tree.branch.repository.has_revision(revision_id))
142
        # the revision id must be set on the inventory when saving it. This
143
        # does not precisely test that - a repository that wants to can add it
144
        # on deserialisation, but thats all the current contract guarantees
145
        # anyway.
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
146
        self.assertEqual(
147
            revision_id,
148
            tree.branch.repository.revision_tree(revision_id).get_revision_id())
3775.2.6 by Robert Collins
CommitBuilder can specify a revision_id with record_iter_changes.
149
5222.1.1 by Aaron Bentley
Refuse to commit trees with no root.
150
    def test_commit_without_root_errors(self):
151
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
152
        with tree.lock_write():
5222.1.1 by Aaron Bentley
Refuse to commit trees with no root.
153
            builder = tree.branch.get_commit_builder([])
7143.15.2 by Jelmer Vernooij
Run autopep8.
154
5222.1.1 by Aaron Bentley
Refuse to commit trees with no root.
155
            def do_commit():
156
                try:
157
                    list(builder.record_iter_changes(
158
                        tree, tree.last_revision(), []))
159
                    builder.finish_inventory()
160
                except:
161
                    builder.abort()
162
                    raise
6202.2.1 by Jelmer Vernooij
Commit in commit builder test to prevent masking errors.
163
                else:
164
                    builder.commit("msg")
5222.1.1 by Aaron Bentley
Refuse to commit trees with no root.
165
            self.assertRaises(errors.RootMissing, do_commit)
166
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
167
    def test_commit_unchanged_root_record_iter_changes(self):
168
        tree = self.make_branch_and_tree(".")
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
169
        old_revision_id = tree.commit('oldrev')
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
170
        tree.lock_write()
3775.2.9 by Robert Collins
CommitBuilder handles deletes via record_iter_entries.
171
        builder = tree.branch.get_commit_builder([old_revision_id])
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
172
        try:
4183.5.4 by Robert Collins
Turn record_iter_changes into a generator to emit file system hashes.
173
            list(builder.record_iter_changes(tree, old_revision_id, []))
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
174
            # Regardless of repository root behaviour we should consider this a
175
            # pointless commit.
3775.2.9 by Robert Collins
CommitBuilder handles deletes via record_iter_entries.
176
            self.assertFalse(builder.any_changes())
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
177
            builder.finish_inventory()
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
178
            builder.commit('rev')
5878.1.1 by Jelmer Vernooij
Avoid inventory usage in a commit builder test.
179
            builder_tree = builder.revision_tree()
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
180
            new_root_id = builder_tree.path2id('')
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
181
            new_root_revision = builder_tree.get_file_revision(u'')
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
182
            if tree.branch.repository.supports_rich_root():
183
                # We should not have seen a new root revision
5878.1.1 by Jelmer Vernooij
Avoid inventory usage in a commit builder test.
184
                self.assertEqual(old_revision_id, new_root_revision)
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
185
            else:
186
                # We should see a new root revision
5878.1.1 by Jelmer Vernooij
Avoid inventory usage in a commit builder test.
187
                self.assertNotEqual(old_revision_id, new_root_revision)
3775.2.7 by Robert Collins
CommitBuilder handles no-change commits to roots properly with record_iter_changes.
188
        finally:
189
            tree.unlock()
190
3775.2.9 by Robert Collins
CommitBuilder handles deletes via record_iter_entries.
191
    def test_record_delete_record_iter_changes(self):
192
        tree = self.make_branch_and_tree(".")
193
        self.build_tree(["foo"])
6770.2.2 by Jelmer Vernooij
Avoid file ids.
194
        tree.add(["foo"])
195
        foo_id = tree.path2id('foo')
3775.2.9 by Robert Collins
CommitBuilder handles deletes via record_iter_entries.
196
        rev_id = tree.commit("added foo")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
197
        with tree.lock_write():
3775.2.9 by Robert Collins
CommitBuilder handles deletes via record_iter_entries.
198
            builder = tree.branch.get_commit_builder([rev_id])
199
            try:
7322.1.7 by Jelmer Vernooij
Fix remaining tests.
200
                delete_change = TreeChange(
201
                    foo_id, ('foo', None), True, (True, False),
202
                    (tree.path2id(''), None),
203
                    ('foo', None), ('file', None),
204
                    (False, None))
4183.5.4 by Robert Collins
Turn record_iter_changes into a generator to emit file system hashes.
205
                list(builder.record_iter_changes(tree, rev_id,
7143.15.2 by Jelmer Vernooij
Run autopep8.
206
                                                 [delete_change]))
6770.2.2 by Jelmer Vernooij
Avoid file ids.
207
                self.assertEqual(("foo", None, foo_id, None),
7143.15.2 by Jelmer Vernooij
Run autopep8.
208
                                 builder.get_basis_delta()[0])
3775.2.9 by Robert Collins
CommitBuilder handles deletes via record_iter_entries.
209
                self.assertTrue(builder.any_changes())
210
                builder.finish_inventory()
211
                rev_id2 = builder.commit('delete foo')
212
            except:
213
                builder.abort()
214
                raise
215
        rev_tree = builder.revision_tree()
216
        rev_tree.lock_read()
217
        self.addCleanup(rev_tree.unlock)
6913.3.5 by Jelmer Vernooij
Avoid calls to path2id.
218
        self.assertFalse(rev_tree.is_versioned('foo'))
3775.2.9 by Robert Collins
CommitBuilder handles deletes via record_iter_entries.
219
3775.2.10 by Robert Collins
CommitBuilder gives a revision tree when used with record_iter_contents.
220
    def test_revision_tree_record_iter_changes(self):
221
        tree = self.make_branch_and_tree(".")
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
222
        with tree.lock_write():
3775.2.10 by Robert Collins
CommitBuilder gives a revision tree when used with record_iter_contents.
223
            builder = tree.branch.get_commit_builder([])
224
            try:
4183.5.4 by Robert Collins
Turn record_iter_changes into a generator to emit file system hashes.
225
                list(builder.record_iter_changes(tree,
7143.15.2 by Jelmer Vernooij
Run autopep8.
226
                                                 _mod_revision.NULL_REVISION,
227
                                                 tree.iter_changes(tree.basis_tree())))
3775.2.10 by Robert Collins
CommitBuilder gives a revision tree when used with record_iter_contents.
228
                builder.finish_inventory()
229
                rev_id = builder.commit('foo bar')
230
            except:
231
                builder.abort()
232
                raise
233
            rev_tree = builder.revision_tree()
234
            # Just a couple simple tests to ensure that it actually follows
235
            # the RevisionTree api.
236
            self.assertEqual(rev_id, rev_tree.get_revision_id())
6072.1.1 by Jelmer Vernooij
Various fixes for tests of foreign plugins.
237
            self.assertEqual((), tuple(rev_tree.get_parent_ids()))
3775.2.10 by Robert Collins
CommitBuilder gives a revision tree when used with record_iter_contents.
238
2255.7.65 by Robert Collins
Split test_root_revision_entry into tree and repository portions.
239
    def test_root_entry_has_revision(self):
240
        # test the root revision created and put in the basis
241
        # has the right rev id.
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
242
        # XXX: RBC 20081118 - this test is too big, it depends on the exact
243
        # behaviour of tree methods and so on; it should be written to the
244
        # commit builder interface directly.
2255.7.65 by Robert Collins
Split test_root_revision_entry into tree and repository portions.
245
        tree = self.make_branch_and_tree('.')
246
        rev_id = tree.commit('message')
247
        basis_tree = tree.basis_tree()
248
        basis_tree.lock_read()
249
        self.addCleanup(basis_tree.unlock)
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
250
        self.assertEqual(rev_id, basis_tree.get_file_revision(u''))
2255.7.65 by Robert Collins
Split test_root_revision_entry into tree and repository portions.
251
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
252
    def _get_revtrees(self, tree, revision_ids):
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
253
        with tree.lock_read():
2592.3.214 by Robert Collins
Merge bzr.dev.
254
            trees = list(tree.branch.repository.revision_trees(revision_ids))
255
            for _tree in trees:
256
                _tree.lock_read()
257
                self.addCleanup(_tree.unlock)
258
            return trees
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
259
260
    def test_last_modified_revision_after_commit_root_unchanged(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
261
        # commiting without changing the root does not change the
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
262
        # last modified except on non-rich-root-repositories.
263
        tree = self.make_branch_and_tree('.')
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
264
        rev1 = tree.commit('rev1')
265
        rev2 = tree.commit('rev2')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
266
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
267
        self.assertEqual(rev1, tree1.get_file_revision(u''))
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
268
        if tree.branch.repository.supports_rich_root():
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
269
            self.assertEqual(rev1, tree2.get_file_revision(u''))
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
270
        else:
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
271
            self.assertEqual(rev2, tree2.get_file_revision(u''))
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
272
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
273
    def _add_commit_check_unchanged(self, tree, name):
6770.2.3 by Jelmer Vernooij
Fix file ids.
274
        tree.add([name])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
275
        self._commit_check_unchanged(tree, name, tree.path2id(name))
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
276
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
277
    def _commit_check_unchanged(self, tree, name, file_id):
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
278
        rev1 = tree.commit('rev1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
279
        rev2 = self.mini_commit_record_iter_changes(
280
            tree, name, name, False, False)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
281
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
6913.3.5 by Jelmer Vernooij
Avoid calls to path2id.
282
        self.assertEqual(rev1, tree1.get_file_revision(name))
283
        self.assertEqual(rev1, tree2.get_file_revision(name))
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
284
        expected_graph = {}
285
        expected_graph[(file_id, rev1)] = ()
286
        self.assertFileGraph(expected_graph, tree, (file_id, rev1))
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
287
288
    def test_last_modified_revision_after_commit_dir_unchanged(self):
289
        # committing without changing a dir does not change the last modified.
290
        tree = self.make_branch_and_tree('.')
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
291
        if not tree.has_versioned_directories():
292
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
293
                'Format does not support versioned directories')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
294
        self.build_tree(['dir/'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
295
        self._add_commit_check_unchanged(tree, 'dir')
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
296
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
297
    def test_last_modified_revision_after_commit_dir_contents_unchanged(self):
298
        # committing without changing a dir does not change the last modified
299
        # of the dir even the dirs contents are changed.
300
        tree = self.make_branch_and_tree('.')
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
301
        self.build_tree(['dir/', 'dir/orig'])
302
        tree.add(['dir', 'dir/orig'])
6770.2.4 by Jelmer Vernooij
Fix remaining test.
303
        dir_id = tree.path2id('dir')
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
304
        rev1 = tree.commit('rev1')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
305
        self.build_tree(['dir/content'])
6770.2.4 by Jelmer Vernooij
Fix remaining test.
306
        tree.add(['dir/content'])
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
307
        rev2 = tree.commit('rev2')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
308
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
309
        self.assertEqual(rev1, tree1.get_file_revision('dir'))
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
310
        self.assertEqual(rev1, tree2.get_file_revision('dir'))
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
311
        expected_graph = {(dir_id, rev1): ()}
6770.2.4 by Jelmer Vernooij
Fix remaining test.
312
        self.assertFileGraph(expected_graph, tree, (dir_id, rev1))
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
313
314
    def test_last_modified_revision_after_commit_file_unchanged(self):
315
        # committing without changing a file does not change the last modified.
316
        tree = self.make_branch_and_tree('.')
317
        self.build_tree(['file'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
318
        self._add_commit_check_unchanged(tree, 'file')
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
319
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
320
    def test_last_modified_revision_after_commit_link_unchanged(self):
321
        # committing without changing a link does not change the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
322
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
323
        tree = self.make_branch_and_tree('.')
324
        os.symlink('target', 'link')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
325
        self._add_commit_check_unchanged(tree, 'link')
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
326
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
327
    def test_last_modified_revision_after_commit_reference_unchanged(self):
328
        # committing without changing a subtree does not change the last
329
        # modified.
330
        tree = self.make_branch_and_tree('.')
331
        subtree = self.make_reference('reference')
6926.2.8 by Jelmer Vernooij
Fix some more tests.
332
        subtree.commit('')
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
333
        try:
334
            tree.add_reference(subtree)
335
            self._commit_check_unchanged(tree, 'reference',
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
336
                                         subtree.path2id(''))
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
337
        except errors.UnsupportedOperation:
338
            return
339
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
340
    def _add_commit_renamed_check_changed(self, tree, name,
7143.15.2 by Jelmer Vernooij
Run autopep8.
341
                                          expect_fs_hash=False):
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
342
        def rename():
343
            tree.rename_one(name, 'new_' + name)
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
344
        self._add_commit_change_check_changed(tree,
7143.15.2 by Jelmer Vernooij
Run autopep8.
345
                                              (name, 'new_' + name), rename,
346
                                              expect_fs_hash=expect_fs_hash)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
347
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
348
    def _commit_renamed_check_changed(self, tree, name,
7143.15.2 by Jelmer Vernooij
Run autopep8.
349
                                      expect_fs_hash=False):
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
350
        def rename():
351
            tree.rename_one(name, 'new_' + name)
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
352
        self._commit_change_check_changed(tree, [name, 'new_' + name],
7143.15.2 by Jelmer Vernooij
Run autopep8.
353
                                          rename, expect_fs_hash=expect_fs_hash)
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
354
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
355
    def test_last_modified_revision_after_rename_dir_changes(self):
356
        # renaming a dir changes the last modified.
357
        tree = self.make_branch_and_tree('.')
6915.3.1 by Jelmer Vernooij
Skip tests that require versioned directories.
358
        if not tree.has_versioned_directories():
359
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
360
                'Format does not support versioned directories')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
361
        self.build_tree(['dir/'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
362
        self._add_commit_renamed_check_changed(tree, 'dir')
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
363
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
364
    def test_last_modified_revision_after_rename_file_changes(self):
365
        # renaming a file changes the last modified.
366
        tree = self.make_branch_and_tree('.')
367
        self.build_tree(['file'])
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
368
        self._add_commit_renamed_check_changed(tree, 'file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
369
                                               expect_fs_hash=True)
3775.2.12 by Robert Collins
CommitBuilder.record_iter_changes handles renamed files.
370
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
371
    def test_last_modified_revision_after_rename_link_changes(self):
372
        # renaming a link changes the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
373
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
374
        tree = self.make_branch_and_tree('.')
375
        os.symlink('target', 'link')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
376
        self._add_commit_renamed_check_changed(tree, 'link')
3775.2.13 by Robert Collins
CommitBuilder.record_iter_changes handles renamed symlinks.
377
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
378
    def test_last_modified_revision_after_rename_ref_changes(self):
379
        # renaming a reference changes the last modified.
380
        tree = self.make_branch_and_tree('.')
381
        subtree = self.make_reference('reference')
6926.2.8 by Jelmer Vernooij
Fix some more tests.
382
        subtree.commit('')
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
383
        try:
384
            tree.add_reference(subtree)
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
385
            self._commit_renamed_check_changed(tree, 'reference')
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
386
        except errors.UnsupportedOperation:
387
            return
388
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
389
    def _add_commit_reparent_check_changed(self, tree, name,
7143.15.2 by Jelmer Vernooij
Run autopep8.
390
                                           expect_fs_hash=False):
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
391
        self.build_tree(['newparent/'])
392
        tree.add(['newparent'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
393
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
394
        def reparent():
395
            tree.rename_one(name, 'newparent/new_' + name)
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
396
        self._add_commit_change_check_changed(
7143.15.2 by Jelmer Vernooij
Run autopep8.
397
            tree, (name, 'newparent/new_' + name), reparent,
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
398
            expect_fs_hash=expect_fs_hash)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
399
400
    def test_last_modified_revision_after_reparent_dir_changes(self):
401
        # reparenting a dir changes the last modified.
402
        tree = self.make_branch_and_tree('.')
6883.22.17 by Jelmer Vernooij
Cope with directory test.
403
        if not tree.has_versioned_directories():
404
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
405
                'Format does not support versioned directories')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
406
        self.build_tree(['dir/'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
407
        self._add_commit_reparent_check_changed(tree, 'dir')
3775.2.14 by Robert Collins
CommitBuilder.record_iter_changes handles reparented directories.
408
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
409
    def test_last_modified_revision_after_reparent_file_changes(self):
410
        # reparenting a file changes the last modified.
411
        tree = self.make_branch_and_tree('.')
412
        self.build_tree(['file'])
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
413
        self._add_commit_reparent_check_changed(tree, 'file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
414
                                                expect_fs_hash=True)
3775.2.15 by Robert Collins
CommitBuilder.record_iter_changes handles reparented files.
415
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
416
    def test_last_modified_revision_after_reparent_link_changes(self):
417
        # reparenting a link changes the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
418
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
419
        tree = self.make_branch_and_tree('.')
420
        os.symlink('target', 'link')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
421
        self._add_commit_reparent_check_changed(tree, 'link')
3775.2.16 by Robert Collins
CommitBuilder.record_iter_changes handles reparented symlinks.
422
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
423
    def _add_commit_change_check_changed(self, tree, names, changer,
7143.15.2 by Jelmer Vernooij
Run autopep8.
424
                                         expect_fs_hash=False):
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
425
        tree.add([names[0]])
426
        self.assertTrue(tree.is_versioned(names[0]))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
427
        self._commit_change_check_changed(
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
428
            tree, names,
429
            changer, expect_fs_hash=expect_fs_hash)
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
430
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
431
    def _commit_change_check_changed(self, tree, names, changer,
432
                                     expect_fs_hash=False):
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
433
        rev1 = tree.commit('rev1')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
434
        changer()
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
435
        rev2 = self.mini_commit_record_iter_changes(
7143.15.2 by Jelmer Vernooij
Run autopep8.
436
            tree, names[0], names[1], expect_fs_hash=expect_fs_hash)
2871.1.3 by Robert Collins
* The CommitBuilder method ``record_entry_contents`` now returns summary
437
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
438
        self.assertEqual(rev1, tree1.get_file_revision(names[0]))
439
        self.assertEqual(rev2, tree2.get_file_revision(names[1]))
440
        file_id = tree1.path2id(names[0])
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
441
        expected_graph = {}
442
        expected_graph[(file_id, rev1)] = ()
443
        expected_graph[(file_id, rev2)] = ((file_id, rev1),)
444
        self.assertFileGraph(expected_graph, tree, (file_id, rev2))
2871.1.3 by Robert Collins
* The CommitBuilder method ``record_entry_contents`` now returns summary
445
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
446
    def mini_commit_record_iter_changes(self, tree, name, new_name,
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
447
                                        records_version=True,
448
                                        delta_against_basis=True,
449
                                        expect_fs_hash=False):
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
450
        """Perform a miniature commit looking for record entry results.
451
452
        This version uses the record_iter_changes interface.
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
453
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
454
        :param tree: The tree to commit.
455
        :param name: The path in the basis tree of the tree being committed.
456
        :param new_name: The path in the tree being committed.
457
        :param records_version: True if the commit of new_name is expected to
458
            record a new version.
459
        :param delta_against_basis: True of the commit of new_name is expected
460
            to have a delta against the basis.
4183.5.4 by Robert Collins
Turn record_iter_changes into a generator to emit file system hashes.
461
        :param expect_fs_hash: If true, looks for a fs hash output from
462
            record_iter_changes.
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
463
        """
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
464
        with tree.lock_write():
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
465
            # mini manual commit here so we can check the return of
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
466
            # record_iter_changes
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
467
            parent_ids = tree.get_parent_ids()
468
            builder = tree.branch.get_commit_builder(parent_ids)
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
469
            try:
470
                parent_tree = tree.basis_tree()
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
471
                with parent_tree.lock_read():
472
                    changes = list(tree.iter_changes(parent_tree))
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
473
                result = list(builder.record_iter_changes(tree, parent_ids[0],
7143.15.2 by Jelmer Vernooij
Run autopep8.
474
                                                          changes))
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
475
                file_id = tree.path2id(new_name)
476
                self.assertIsNot(None, file_id)
6883.22.19 by Jelmer Vernooij
Add records_per_file_revision attribute.
477
                if isinstance(tree, inventorytree.InventoryTree):
478
                    # TODO(jelmer): record_iter_changes shouldn't yield
479
                    # data that is WorkingTree-format-specific and uses file ids.
480
                    if expect_fs_hash:
481
                        tree_file_stat = tree.get_file_with_stat(new_name)
482
                        tree_file_stat[0].close()
483
                        self.assertLength(1, result)
484
                        result = result[0]
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
485
                        self.assertEqual(result[0], new_name)
7143.15.2 by Jelmer Vernooij
Run autopep8.
486
                        self.assertEqual(
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
487
                            result[1][0], tree.get_file_sha1(new_name))
488
                        self.assertEqualStat(result[1][1], tree_file_stat[1])
6883.22.19 by Jelmer Vernooij
Add records_per_file_revision attribute.
489
                    else:
490
                        self.assertEqual([], result)
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
491
                builder.finish_inventory()
492
                if tree.branch.repository._format.supports_full_versioned_files:
493
                    inv_key = (builder._new_revision_id,)
494
                    inv_sha1 = tree.branch.repository.inventories.get_sha1s(
7143.15.2 by Jelmer Vernooij
Run autopep8.
495
                        [inv_key])[inv_key]
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
496
                    self.assertEqual(inv_sha1, builder.inv_sha1)
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
497
                rev2 = builder.commit('rev2')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
498
            except BaseException:
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
499
                builder.abort()
500
                raise
6437.12.1 by Jelmer Vernooij
Use CommitBuilder.get_basis_delta rather than private CommitBuilder._basis_delta.
501
            delta = builder.get_basis_delta()
502
            delta_dict = dict((change[2], change) for change in delta)
6883.22.19 by Jelmer Vernooij
Add records_per_file_revision attribute.
503
            if tree.branch.repository._format.records_per_file_revision:
7143.15.2 by Jelmer Vernooij
Run autopep8.
504
                version_recorded = (file_id in delta_dict
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
505
                                    and delta_dict[file_id][3] is not None
506
                                    and delta_dict[file_id][3].revision == rev2)
6883.22.19 by Jelmer Vernooij
Add records_per_file_revision attribute.
507
                if records_version:
508
                    self.assertTrue(version_recorded)
509
                else:
510
                    self.assertFalse(version_recorded)
6437.12.1 by Jelmer Vernooij
Use CommitBuilder.get_basis_delta rather than private CommitBuilder._basis_delta.
511
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
512
            revtree = builder.revision_tree()
7143.15.2 by Jelmer Vernooij
Run autopep8.
513
            new_entry = next(revtree.iter_entries_by_dir(
514
                specific_files=[new_name]))[1]
6883.16.1 by Jelmer Vernooij
commit builder test improvements:
515
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
516
            if delta_against_basis:
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
517
                if tree.supports_rename_tracking() or name == new_name:
518
                    expected_delta = (name, new_name, file_id, new_entry)
519
                else:
520
                    expected_delta = (None, new_name, file_id, new_entry)
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
521
                self.assertEqual(expected_delta, delta_dict[file_id])
522
            else:
523
                expected_delta = None
6883.22.19 by Jelmer Vernooij
Add records_per_file_revision attribute.
524
                if tree.branch.repository._format.records_per_file_revision:
525
                    self.assertFalse(version_recorded)
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
526
            tree.set_parent_ids([rev2])
527
        return rev2
528
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
529
    def assertFileGraph(self, expected_graph, tree, tip):
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
530
        # all the changes that have occured should be in the ancestry
531
        # (closest to a public per-file graph API we have today)
532
        tree.lock_read()
533
        self.addCleanup(tree.unlock)
5815.5.9 by Jelmer Vernooij
Remove dependencies on texts.
534
        g = dict(tree.branch.repository.get_file_graph().iter_ancestry([tip]))
5010.2.24 by Vincent Ladeuil
Fix imports in per_repository/test_commit_builder.py.
535
        self.assertEqual(expected_graph, g)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
536
537
    def test_last_modified_revision_after_content_file_changes(self):
538
        # altering a file changes the last modified.
539
        tree = self.make_branch_and_tree('.')
540
        self.build_tree(['file'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
541
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
542
        def change_file():
6973.6.3 by Jelmer Vernooij
More fixes.
543
            tree.put_file_bytes_non_atomic('file', b'new content')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
544
        self._add_commit_change_check_changed(tree, ('file', 'file'), change_file,
7143.15.2 by Jelmer Vernooij
Run autopep8.
545
                                              expect_fs_hash=True)
3775.2.17 by Robert Collins
CommitBuilder.record_iter_changes handles changed files.
546
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
547
    def _test_last_mod_rev_after_content_link_changes(
7143.15.2 by Jelmer Vernooij
Run autopep8.
548
            self, link, target, newtarget):
3775.2.18 by Robert Collins
CommitBuilder.record_iter_changes handles changed symlinks.
549
        # changing a link changes the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
550
        self.requireFeature(features.SymlinkFeature)
3775.2.18 by Robert Collins
CommitBuilder.record_iter_changes handles changed symlinks.
551
        tree = self.make_branch_and_tree('.')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
552
        os.symlink(target, link)
7143.15.2 by Jelmer Vernooij
Run autopep8.
553
3775.2.18 by Robert Collins
CommitBuilder.record_iter_changes handles changed symlinks.
554
        def change_link():
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
555
            os.unlink(link)
556
            os.symlink(newtarget, link)
557
        self._add_commit_change_check_changed(
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
558
            tree, (link, link), change_link)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
559
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
560
    def test_last_modified_rev_after_content_link_changes(self):
561
        self._test_last_mod_rev_after_content_link_changes(
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
562
            'link', 'target', 'newtarget')
563
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
564
    def test_last_modified_rev_after_content_unicode_link_changes(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
565
        self.requireFeature(features.UnicodeFilenameFeature)
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
566
        self._test_last_mod_rev_after_content_link_changes(
6770.2.1 by Jelmer Vernooij
Avoid setting file ids.
567
            u'li\u1234nk', u'targ\N{Euro Sign}t', u'n\N{Euro Sign}wtarget')
3775.2.18 by Robert Collins
CommitBuilder.record_iter_changes handles changed symlinks.
568
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
569
    def _commit_sprout(self, tree, name):
6770.2.3 by Jelmer Vernooij
Fix file ids.
570
        tree.add([name])
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
571
        rev_id = tree.commit('rev')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
572
        return rev_id, tree.controldir.sprout('t2').open_workingtree()
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
573
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
574
    def _rename_in_tree(self, tree, name, message):
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
575
        tree.rename_one(name, 'new_' + name)
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
576
        return tree.commit(message)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
577
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
578
    def _commit_sprout_rename_merge(self, tree1, name, expect_fs_hash=False):
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
579
        """Do a rename in both trees."""
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
580
        rev1, tree2 = self._commit_sprout(tree1, name)
6770.2.3 by Jelmer Vernooij
Fix file ids.
581
        file_id = tree2.path2id(name)
6852.2.1 by Jelmer Vernooij
Allow formats to not support custom revision properties.
582
        self.assertIsNot(None, file_id)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
583
        # change both sides equally
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
584
        rev2 = self._rename_in_tree(tree1, name, 'rev2')
585
        rev3 = self._rename_in_tree(tree2, name, 'rev3')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
586
        tree1.merge_from_branch(tree2.branch)
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
587
        rev4 = self.mini_commit_record_iter_changes(
588
            tree1, 'new_' + name, 'new_' + name,
589
            expect_fs_hash=expect_fs_hash,
590
            delta_against_basis=tree1.supports_rename_tracking())
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
591
        tree3, = self._get_revtrees(tree1, [rev4])
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
592
        expected_graph = {}
6883.22.18 by Jelmer Vernooij
Support handling renames.
593
        if tree1.supports_rename_tracking():
594
            self.assertEqual(rev4, tree3.get_file_revision('new_' + name))
595
            expected_graph[(file_id, rev1)] = ()
596
            expected_graph[(file_id, rev2)] = ((file_id, rev1),)
597
            expected_graph[(file_id, rev3)] = ((file_id, rev1),)
7143.15.2 by Jelmer Vernooij
Run autopep8.
598
            expected_graph[(file_id, rev4)] = (
599
                (file_id, rev2), (file_id, rev3),)
6883.22.18 by Jelmer Vernooij
Support handling renames.
600
        else:
601
            self.assertEqual(rev2, tree3.get_file_revision('new_' + name))
602
            expected_graph[(file_id, rev4)] = ()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
603
        self.assertFileGraph(expected_graph, tree1, (file_id, rev4))
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
604
605
    def test_last_modified_revision_after_merge_dir_changes(self):
606
        # merge a dir changes the last modified.
607
        tree1 = self.make_branch_and_tree('t1')
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
608
        if not tree1.has_versioned_directories():
609
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
610
                'Format does not support versioned directories')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
611
        self.build_tree(['t1/dir/'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
612
        self._commit_sprout_rename_merge(tree1, 'dir')
3775.2.19 by Robert Collins
CommitBuilder.record_iter_changes handles merged directories.
613
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
614
    def test_last_modified_revision_after_merge_file_changes(self):
615
        # merge a file changes the last modified.
616
        tree1 = self.make_branch_and_tree('t1')
617
        self.build_tree(['t1/file'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
618
        self._commit_sprout_rename_merge(tree1, 'file', expect_fs_hash=True)
3775.2.20 by Robert Collins
CommitBuilder.record_iter_changes handles merged files.
619
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
620
    def test_last_modified_revision_after_merge_link_changes(self):
621
        # merge a link changes the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
622
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
623
        tree1 = self.make_branch_and_tree('t1')
624
        os.symlink('target', 't1/link')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
625
        self._commit_sprout_rename_merge(tree1, 'link')
3775.2.21 by Robert Collins
CommitBuilder.record_iter_changes handles merged symlinks.
626
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
627
    def _commit_sprout_rename_merge_converged(self, tree1, name):
3775.2.22 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch directories.
628
        # Make a merge which just incorporates a change from a branch:
629
        # The per-file graph is straight line, and no alteration occurs
630
        # in the inventory.
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
631
        # Part 1: change in the merged branch.
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
632
        rev1, tree2 = self._commit_sprout(tree1, name)
6770.2.3 by Jelmer Vernooij
Fix file ids.
633
        file_id = tree2.path2id(name)
6852.2.1 by Jelmer Vernooij
Allow formats to not support custom revision properties.
634
        self.assertIsNot(None, file_id)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
635
        # change on the other side to merge back
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
636
        rev2 = self._rename_in_tree(tree2, name, 'rev2')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
637
        tree1.merge_from_branch(tree2.branch)
7143.15.2 by Jelmer Vernooij
Run autopep8.
638
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
639
        def _check_graph(in_tree, changed_in_tree):
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
640
            rev3 = self.mini_commit_record_iter_changes(
7143.15.2 by Jelmer Vernooij
Run autopep8.
641
                in_tree, name, 'new_' + name, False,
642
                delta_against_basis=changed_in_tree)
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
643
            tree3, = self._get_revtrees(in_tree, [rev2])
7143.15.15 by Jelmer Vernooij
Merge trunk.
644
            self.assertEqual(rev2, tree3.get_file_revision('new_' + name))
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
645
            expected_graph = {}
646
            expected_graph[(file_id, rev1)] = ()
647
            expected_graph[(file_id, rev2)] = ((file_id, rev1),)
648
            self.assertFileGraph(expected_graph, in_tree, (file_id, rev2))
649
        _check_graph(tree1, True)
650
        # Part 2: change in the merged into branch - we use tree2 that has a
651
        # change to name, branch tree1 and give it an unrelated change, then
652
        # merge that to t2.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
653
        other_tree = tree1.controldir.sprout('t3').open_workingtree()
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
654
        other_rev = other_tree.commit('other_rev')
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
655
        tree2.merge_from_branch(other_tree.branch)
656
        _check_graph(tree2, False)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
657
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
658
    def _commit_sprout_make_merge(self, tree1, make):
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
659
        # Make a merge which incorporates the addition of a new object to
660
        # another branch. The per-file graph shows no additional change
661
        # in the merge because its a straight line.
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
662
        rev1 = tree1.commit('rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
663
        tree2 = tree1.controldir.sprout('t2').open_workingtree()
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
664
        # make and commit on the other side to merge back
665
        make('t2/name')
6770.2.2 by Jelmer Vernooij
Avoid file ids.
666
        tree2.add(['name'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
667
        self.assertTrue(tree2.is_versioned('name'))
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
668
        rev2 = tree2.commit('rev2')
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
669
        tree1.merge_from_branch(tree2.branch)
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
670
        rev3 = self.mini_commit_record_iter_changes(tree1, None, 'name', False)
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
671
        tree3, = self._get_revtrees(tree1, [rev2])
672
        # in rev2, name should be only changed in rev2
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
673
        self.assertEqual(rev2, tree3.get_file_revision('name'))
674
        file_id = tree2.path2id('name')
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
675
        expected_graph = {}
676
        expected_graph[(file_id, rev2)] = ()
677
        self.assertFileGraph(expected_graph, tree1, (file_id, rev2))
678
679
    def test_last_modified_revision_after_converged_merge_dir_unchanged(self):
680
        # merge a dir that changed preserves the last modified.
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
681
        tree1 = self.make_branch_and_tree('t1')
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
682
        if not tree1.has_versioned_directories():
683
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
684
                'Format does not support versioned directories')
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
685
        self.build_tree(['t1/dir/'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
686
        self._commit_sprout_rename_merge_converged(tree1, 'dir')
3775.2.22 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch directories.
687
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
688
    def test_last_modified_revision_after_converged_merge_file_unchanged(self):
689
        # merge a file that changed preserves the last modified.
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
690
        tree1 = self.make_branch_and_tree('t1')
691
        self.build_tree(['t1/file'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
692
        self._commit_sprout_rename_merge_converged(tree1, 'file')
3775.2.23 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch files.
693
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
694
    def test_last_modified_revision_after_converged_merge_link_unchanged(self):
695
        # merge a link that changed preserves the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
696
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
697
        tree1 = self.make_branch_and_tree('t1')
698
        os.symlink('target', 't1/link')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
699
        self._commit_sprout_rename_merge_converged(tree1, 'link')
3775.2.24 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch symlinks.
700
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
701
    def test_last_modified_revision_after_merge_new_dir_unchanged(self):
702
        # merge a new dir does not change the last modified.
703
        tree1 = self.make_branch_and_tree('t1')
6915.3.1 by Jelmer Vernooij
Skip tests that require versioned directories.
704
        if not tree1.has_versioned_directories():
705
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
706
                'Format does not support versioned directories')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
707
        self._commit_sprout_make_merge(tree1, self.make_dir)
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
708
709
    def test_last_modified_revision_after_merge_new_file_unchanged(self):
710
        # merge a new file does not change the last modified.
711
        tree1 = self.make_branch_and_tree('t1')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
712
        self._commit_sprout_make_merge(tree1, self.make_file)
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
713
714
    def test_last_modified_revision_after_merge_new_link_unchanged(self):
715
        # merge a new link does not change the last modified.
716
        tree1 = self.make_branch_and_tree('t1')
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
717
        self._commit_sprout_make_merge(tree1, self.make_link)
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
718
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
719
    def make_dir(self, name):
720
        self.build_tree([name + '/'])
721
722
    def make_file(self, name):
723
        self.build_tree([name])
724
725
    def make_link(self, name):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
726
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
727
        os.symlink('target', name)
728
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
729
    def make_reference(self, name):
6926.2.11 by Jelmer Vernooij
Don't rely on 1.9-rich-root.
730
        tree = self.make_branch_and_tree(name)
731
        if not tree.branch.repository._format.rich_root_data:
732
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
733
                'format does not support rich roots')
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
734
        tree.commit('foo')
735
        return tree
736
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
737
    def _check_kind_change(self, make_before, make_after, expect_fs_hash=False):
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
738
        tree = self.make_branch_and_tree('.')
739
        path = 'name'
740
        make_before(path)
2831.5.2 by Vincent Ladeuil
Review feedback.
741
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
742
        def change_kind():
6164.2.3 by Jelmer Vernooij
Use rmtree, since some vcses include control directories in every directory.
743
            if osutils.file_kind(path) == "directory":
744
                osutils.rmtree(path)
745
            else:
746
                osutils.delete_any(path)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
747
            make_after(path)
2831.5.2 by Vincent Ladeuil
Review feedback.
748
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
749
        self._add_commit_change_check_changed(tree, (path, path), change_kind,
7143.15.2 by Jelmer Vernooij
Run autopep8.
750
                                              expect_fs_hash=expect_fs_hash)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
751
752
    def test_last_modified_dir_file(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
753
        if not self.repository_format.supports_versioned_directories:
754
            # TODO(jelmer): Perhaps test this by creating a directory
755
            # with a file in it?
756
            raise tests.TestNotApplicable(
757
                'format does not support versioned directories')
6217.2.1 by Jelmer Vernooij
Allow tree implementations to not support kind changes.
758
        try:
759
            self._check_kind_change(self.make_dir, self.make_file,
7143.15.2 by Jelmer Vernooij
Run autopep8.
760
                                    expect_fs_hash=True)
6217.2.1 by Jelmer Vernooij
Allow tree implementations to not support kind changes.
761
        except errors.UnsupportedKindChange:
762
            raise tests.TestSkipped(
763
                "tree does not support changing entry kind from "
764
                "directory to file")
3775.2.25 by Robert Collins
CommitBuilder.record_iter_changes handles directories becoming files and links.
765
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
766
    def test_last_modified_dir_link(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
767
        if not self.repository_format.supports_versioned_directories:
768
            # TODO(jelmer): Perhaps test this by creating a directory
769
            # with a file in it?
770
            raise tests.TestNotApplicable(
771
                'format does not support versioned directories')
6217.2.1 by Jelmer Vernooij
Allow tree implementations to not support kind changes.
772
        try:
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
773
            self._check_kind_change(self.make_dir, self.make_link)
6217.2.1 by Jelmer Vernooij
Allow tree implementations to not support kind changes.
774
        except errors.UnsupportedKindChange:
775
            raise tests.TestSkipped(
776
                "tree does not support changing entry kind from "
777
                "directory to link")
3775.2.25 by Robert Collins
CommitBuilder.record_iter_changes handles directories becoming files and links.
778
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
779
    def test_last_modified_link_file(self):
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
780
        self._check_kind_change(self.make_link, self.make_file,
7143.15.2 by Jelmer Vernooij
Run autopep8.
781
                                expect_fs_hash=True)
3775.2.26 by Robert Collins
CommitBuilder.record_iter_changes handles links becomes directories and files.
782
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
783
    def test_last_modified_link_dir(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
784
        if not self.repository_format.supports_versioned_directories:
785
            # TODO(jelmer): Perhaps test this by creating a directory
786
            # with a file in it?
787
            raise tests.TestNotApplicable(
788
                'format does not support versioned directories')
789
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
790
        self._check_kind_change(self.make_link, self.make_dir)
3775.2.26 by Robert Collins
CommitBuilder.record_iter_changes handles links becomes directories and files.
791
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
792
    def test_last_modified_file_dir(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
793
        if not self.repository_format.supports_versioned_directories:
794
            # TODO(jelmer): Perhaps test this by creating a directory
795
            # with a file in it?
796
            raise tests.TestNotApplicable(
797
                'format does not support versioned directories')
798
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
799
        self._check_kind_change(self.make_file, self.make_dir)
3775.2.27 by Robert Collins
CommitBuilder.record_iter_changes handles files becoming directories and links.
800
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
801
    def test_last_modified_file_link(self):
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
802
        self._check_kind_change(self.make_file, self.make_link)
3775.2.28 by Robert Collins
Merge .dev.
803
3831.1.1 by John Arbash Meinel
Before allowing commit to succeed, verify the texts will be 'safe'.
804
    def test_get_commit_builder_with_invalid_revprops(self):
805
        branch = self.make_branch('.')
806
        branch.repository.lock_write()
807
        self.addCleanup(branch.repository.unlock)
808
        self.assertRaises(ValueError, branch.repository.get_commit_builder,
7143.15.2 by Jelmer Vernooij
Run autopep8.
809
                          branch, [], branch.get_config_stack(),
810
                          revprops={'invalid': u'property\rwith\r\ninvalid chars'})
3831.1.1 by John Arbash Meinel
Before allowing commit to succeed, verify the texts will be 'safe'.
811
7490.74.2 by Jelmer Vernooij
Use surrogateescape in revprops.
812
    def test_get_commit_builder_with_surrogateescape(self):
7490.74.3 by Jelmer Vernooij
Fix tests.
813
        if not PY3:
814
            self.skipTest('python 2 does not have surrogateescape')
7490.74.2 by Jelmer Vernooij
Use surrogateescape in revprops.
815
        tree = self.make_branch_and_tree(".")
816
        with tree.lock_write():
817
            builder = tree.branch.get_commit_builder([], revprops={
818
                'invalid': u'property' + b'\xc0'.decode('utf-8', 'surrogateescape')})
819
            list(builder.record_iter_changes(tree, tree.last_revision(),
820
                                             tree.iter_changes(tree.basis_tree())))
821
            builder.finish_inventory()
822
            try:
823
                rev_id = builder.commit('foo bar blah')
824
            except NotImplementedError:
825
                raise tests.TestNotApplicable(
826
                    'Format does not support revision properties')
827
        rev = tree.branch.repository.get_revision(rev_id)
828
        self.assertEqual('foo bar blah', rev.message)
829
3831.1.1 by John Arbash Meinel
Before allowing commit to succeed, verify the texts will be 'safe'.
830
    def test_commit_builder_commit_with_invalid_message(self):
831
        branch = self.make_branch('.')
832
        branch.repository.lock_write()
833
        self.addCleanup(branch.repository.unlock)
834
        builder = branch.repository.get_commit_builder(branch, [],
7143.15.2 by Jelmer Vernooij
Run autopep8.
835
                                                       branch.get_config_stack())
3831.1.1 by John Arbash Meinel
Before allowing commit to succeed, verify the texts will be 'safe'.
836
        self.addCleanup(branch.repository.abort_write_group)
837
        self.assertRaises(ValueError, builder.commit,
7143.15.2 by Jelmer Vernooij
Run autopep8.
838
                          u'Invalid\r\ncommit message\r\n')
4595.4.2 by Robert Collins
Disable commit builders on stacked repositories.
839
5485.4.2 by Martin
Move guard to CommitBuilder.__init__ and test to bt.per_repository
840
    def test_non_ascii_str_committer_rejected(self):
841
        """Ensure an error is raised on a non-ascii byte string committer"""
842
        branch = self.make_branch('.')
843
        branch.repository.lock_write()
844
        self.addCleanup(branch.repository.unlock)
845
        self.assertRaises(UnicodeDecodeError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
846
                          branch.repository.get_commit_builder,
847
                          branch, [], branch.get_config_stack(),
848
                          committer=b"Erik B\xe5gfors <erik@example.com>")
5485.4.2 by Martin
Move guard to CommitBuilder.__init__ and test to bt.per_repository
849
4595.4.2 by Robert Collins
Disable commit builders on stacked repositories.
850
    def test_stacked_repositories_reject_commit_builder(self):
851
        # As per bug 375013, committing to stacked repositories is currently
5557.1.17 by John Arbash Meinel
Fix the test case that was checking we refused to create a commit_builder
852
        # broken if we aren't in a chk repository. So old repositories with
853
        # fallbacks refuse to hand out a commit builder.
4595.4.2 by Robert Collins
Disable commit builders on stacked repositories.
854
        repo_basis = self.make_repository('basis')
855
        branch = self.make_branch('local')
856
        repo_local = branch.repository
857
        try:
858
            repo_local.add_fallback_repository(repo_basis)
859
        except errors.UnstackableRepositoryFormat:
860
            raise tests.TestNotApplicable("not a stackable format.")
5557.1.17 by John Arbash Meinel
Fix the test case that was checking we refused to create a commit_builder
861
        self.addCleanup(repo_local.lock_write().unlock)
862
        if not repo_local._format.supports_chks:
863
            self.assertRaises(errors.BzrError, repo_local.get_commit_builder,
7143.15.2 by Jelmer Vernooij
Run autopep8.
864
                              branch, [], branch.get_config_stack())
5557.1.17 by John Arbash Meinel
Fix the test case that was checking we refused to create a commit_builder
865
        else:
866
            builder = repo_local.get_commit_builder(branch, [],
6351.3.3 by Jelmer Vernooij
Convert more stuff to use config stacks.
867
                                                    branch.get_config_stack())
5557.1.17 by John Arbash Meinel
Fix the test case that was checking we refused to create a commit_builder
868
            builder.abort()
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
869
870
    def test_committer_no_username(self):
871
        # Ensure that when no username is available but a committer is
872
        # supplied, commit works.
7344.1.1 by Martin
Fix tests that need whoami not to be set
873
        override_whoami(self)
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
874
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
875
        with tree.lock_write():
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
876
            # Make sure no username is available.
7336.2.1 by Martin
Split non-ini config methods to bedding
877
            self.assertRaises(errors.NoWhoami, tree.branch.get_commit_builder,
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
878
                              [])
879
            builder = tree.branch.get_commit_builder(
880
                [], committer='me@example.com')
881
            try:
882
                list(builder.record_iter_changes(tree, tree.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
883
                                                 tree.iter_changes(tree.basis_tree())))
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
884
                builder.finish_inventory()
885
            except:
886
                builder.abort()
887
                raise
888
            repo = tree.branch.repository
889
            repo.commit_write_group()