/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()
7467.4.13 by Jelmer Vernooij
Fix last rename tests.
502
            delta_dict = dict((change[1], 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:
7467.4.13 by Jelmer Vernooij
Fix last rename tests.
504
                version_recorded = (new_name in delta_dict
505
                                    and delta_dict[new_name][3] is not None
506
                                    and delta_dict[new_name][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:
7467.4.13 by Jelmer Vernooij
Fix last rename tests.
517
                (delta_old_name, delta_new_name,
518
                 delta_file_id, delta_entry) = delta_dict[new_name]
519
                self.assertEqual(delta_new_name, new_name)
520
                if tree.supports_rename_tracking():
521
                    self.assertEqual(name, delta_old_name)
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
522
                else:
7467.4.13 by Jelmer Vernooij
Fix last rename tests.
523
                    self.assertIn(delta_old_name, (name, None))
524
                if tree.supports_setting_file_ids():
525
                    self.assertEqual(delta_file_id, file_id)
526
                    self.assertEqual(delta_entry.file_id, file_id)
527
                self.assertEqual(delta_entry.kind, new_entry.kind)
528
                self.assertEqual(delta_entry.name, new_entry.name)
529
                self.assertEqual(delta_entry.parent_id, new_entry.parent_id)
530
                if delta_entry.kind == 'file':
531
                    self.assertEqual(delta_entry.text_size, new_entry.text_size)
532
                    self.assertEqual(delta_entry.text_sha1, new_entry.text_sha1)
533
                elif delta_entry.kind == 'symlink':
534
                    self.assertEqual(delta_entry.symlink_target, new_entry.symlink_target)
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
535
            else:
536
                expected_delta = None
6883.22.19 by Jelmer Vernooij
Add records_per_file_revision attribute.
537
                if tree.branch.repository._format.records_per_file_revision:
538
                    self.assertFalse(version_recorded)
3775.2.11 by Robert Collins
CommitBuilder handles renamed directory and unmodified entries with single parents, for record_iter_changes.
539
            tree.set_parent_ids([rev2])
540
        return rev2
541
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.
542
    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.
543
        # all the changes that have occured should be in the ancestry
544
        # (closest to a public per-file graph API we have today)
545
        tree.lock_read()
546
        self.addCleanup(tree.unlock)
5815.5.9 by Jelmer Vernooij
Remove dependencies on texts.
547
        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.
548
        self.assertEqual(expected_graph, g)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
549
550
    def test_last_modified_revision_after_content_file_changes(self):
551
        # altering a file changes the last modified.
552
        tree = self.make_branch_and_tree('.')
553
        self.build_tree(['file'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
554
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
555
        def change_file():
6973.6.3 by Jelmer Vernooij
More fixes.
556
            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.
557
        self._add_commit_change_check_changed(tree, ('file', 'file'), change_file,
7143.15.2 by Jelmer Vernooij
Run autopep8.
558
                                              expect_fs_hash=True)
3775.2.17 by Robert Collins
CommitBuilder.record_iter_changes handles changed files.
559
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
560
    def _test_last_mod_rev_after_content_link_changes(
7143.15.2 by Jelmer Vernooij
Run autopep8.
561
            self, link, target, newtarget):
3775.2.18 by Robert Collins
CommitBuilder.record_iter_changes handles changed symlinks.
562
        # changing a link changes the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
563
        self.requireFeature(features.SymlinkFeature)
3775.2.18 by Robert Collins
CommitBuilder.record_iter_changes handles changed symlinks.
564
        tree = self.make_branch_and_tree('.')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
565
        os.symlink(target, link)
7143.15.2 by Jelmer Vernooij
Run autopep8.
566
3775.2.18 by Robert Collins
CommitBuilder.record_iter_changes handles changed symlinks.
567
        def change_link():
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
568
            os.unlink(link)
569
            os.symlink(newtarget, link)
570
        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.
571
            tree, (link, link), change_link)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
572
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
573
    def test_last_modified_rev_after_content_link_changes(self):
574
        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.
575
            'link', 'target', 'newtarget')
576
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
577
    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
578
        self.requireFeature(features.UnicodeFilenameFeature)
6700.2.1 by Jelmer Vernooij
Remove record_entry_contents tests and infrastructure.
579
        self._test_last_mod_rev_after_content_link_changes(
6770.2.1 by Jelmer Vernooij
Avoid setting file ids.
580
            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.
581
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
582
    def _commit_sprout(self, tree, name):
6770.2.3 by Jelmer Vernooij
Fix file ids.
583
        tree.add([name])
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
584
        rev_id = tree.commit('rev')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
585
        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.
586
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
587
    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.
588
        tree.rename_one(name, 'new_' + name)
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
589
        return tree.commit(message)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
590
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
591
    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.
592
        """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.
593
        rev1, tree2 = self._commit_sprout(tree1, name)
6770.2.3 by Jelmer Vernooij
Fix file ids.
594
        file_id = tree2.path2id(name)
6852.2.1 by Jelmer Vernooij
Allow formats to not support custom revision properties.
595
        self.assertIsNot(None, file_id)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
596
        # change both sides equally
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
597
        rev2 = self._rename_in_tree(tree1, name, 'rev2')
598
        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.
599
        tree1.merge_from_branch(tree2.branch)
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
600
        rev4 = self.mini_commit_record_iter_changes(
601
            tree1, 'new_' + name, 'new_' + name,
602
            expect_fs_hash=expect_fs_hash,
603
            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.
604
        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.
605
        expected_graph = {}
6883.22.18 by Jelmer Vernooij
Support handling renames.
606
        if tree1.supports_rename_tracking():
607
            self.assertEqual(rev4, tree3.get_file_revision('new_' + name))
608
            expected_graph[(file_id, rev1)] = ()
609
            expected_graph[(file_id, rev2)] = ((file_id, rev1),)
610
            expected_graph[(file_id, rev3)] = ((file_id, rev1),)
7143.15.2 by Jelmer Vernooij
Run autopep8.
611
            expected_graph[(file_id, rev4)] = (
612
                (file_id, rev2), (file_id, rev3),)
6883.22.18 by Jelmer Vernooij
Support handling renames.
613
        else:
614
            self.assertEqual(rev2, tree3.get_file_revision('new_' + name))
615
            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.
616
        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.
617
618
    def test_last_modified_revision_after_merge_dir_changes(self):
619
        # merge a dir changes the last modified.
620
        tree1 = self.make_branch_and_tree('t1')
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
621
        if not tree1.has_versioned_directories():
622
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
623
                '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.
624
        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.
625
        self._commit_sprout_rename_merge(tree1, 'dir')
3775.2.19 by Robert Collins
CommitBuilder.record_iter_changes handles merged directories.
626
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
627
    def test_last_modified_revision_after_merge_file_changes(self):
628
        # merge a file changes the last modified.
629
        tree1 = self.make_branch_and_tree('t1')
630
        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.
631
        self._commit_sprout_rename_merge(tree1, 'file', expect_fs_hash=True)
3775.2.20 by Robert Collins
CommitBuilder.record_iter_changes handles merged files.
632
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
633
    def test_last_modified_revision_after_merge_link_changes(self):
634
        # merge a link changes the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
635
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
636
        tree1 = self.make_branch_and_tree('t1')
637
        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.
638
        self._commit_sprout_rename_merge(tree1, 'link')
3775.2.21 by Robert Collins
CommitBuilder.record_iter_changes handles merged symlinks.
639
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
640
    def _commit_sprout_rename_merge_converged(self, tree1, name):
3775.2.22 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch directories.
641
        # Make a merge which just incorporates a change from a branch:
642
        # The per-file graph is straight line, and no alteration occurs
643
        # in the inventory.
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
644
        # 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.
645
        rev1, tree2 = self._commit_sprout(tree1, name)
6770.2.3 by Jelmer Vernooij
Fix file ids.
646
        file_id = tree2.path2id(name)
6852.2.1 by Jelmer Vernooij
Allow formats to not support custom revision properties.
647
        self.assertIsNot(None, file_id)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
648
        # change on the other side to merge back
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
649
        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.
650
        tree1.merge_from_branch(tree2.branch)
7143.15.2 by Jelmer Vernooij
Run autopep8.
651
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
652
        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.
653
            rev3 = self.mini_commit_record_iter_changes(
7143.15.2 by Jelmer Vernooij
Run autopep8.
654
                in_tree, name, 'new_' + name, False,
655
                delta_against_basis=changed_in_tree)
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
656
            tree3, = self._get_revtrees(in_tree, [rev2])
7143.15.15 by Jelmer Vernooij
Merge trunk.
657
            self.assertEqual(rev2, tree3.get_file_revision('new_' + name))
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
658
            expected_graph = {}
659
            expected_graph[(file_id, rev1)] = ()
660
            expected_graph[(file_id, rev2)] = ((file_id, rev1),)
661
            self.assertFileGraph(expected_graph, in_tree, (file_id, rev2))
662
        _check_graph(tree1, True)
663
        # Part 2: change in the merged into branch - we use tree2 that has a
664
        # change to name, branch tree1 and give it an unrelated change, then
665
        # merge that to t2.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
666
        other_tree = tree1.controldir.sprout('t3').open_workingtree()
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
667
        other_rev = other_tree.commit('other_rev')
4183.5.9 by Robert Collins
Fix creating new revisions of files when merging.
668
        tree2.merge_from_branch(other_tree.branch)
669
        _check_graph(tree2, False)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
670
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
671
    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.
672
        # Make a merge which incorporates the addition of a new object to
673
        # another branch. The per-file graph shows no additional change
674
        # in the merge because its a straight line.
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
675
        rev1 = tree1.commit('rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
676
        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.
677
        # make and commit on the other side to merge back
678
        make('t2/name')
6770.2.2 by Jelmer Vernooij
Avoid file ids.
679
        tree2.add(['name'])
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
680
        self.assertTrue(tree2.is_versioned('name'))
6915.3.2 by Jelmer Vernooij
Set commit message for entropy.
681
        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.
682
        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.
683
        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.
684
        tree3, = self._get_revtrees(tree1, [rev2])
685
        # 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.
686
        self.assertEqual(rev2, tree3.get_file_revision('name'))
687
        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.
688
        expected_graph = {}
689
        expected_graph[(file_id, rev2)] = ()
690
        self.assertFileGraph(expected_graph, tree1, (file_id, rev2))
691
692
    def test_last_modified_revision_after_converged_merge_dir_unchanged(self):
693
        # 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.
694
        tree1 = self.make_branch_and_tree('t1')
6883.14.2 by Jelmer Vernooij
Fix commitbuilder tests.
695
        if not tree1.has_versioned_directories():
696
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
697
                '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.
698
        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.
699
        self._commit_sprout_rename_merge_converged(tree1, 'dir')
3775.2.22 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch directories.
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_converged_merge_file_unchanged(self):
702
        # 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.
703
        tree1 = self.make_branch_and_tree('t1')
704
        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.
705
        self._commit_sprout_rename_merge_converged(tree1, 'file')
3775.2.23 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch files.
706
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
707
    def test_last_modified_revision_after_converged_merge_link_unchanged(self):
708
        # merge a link that changed preserves the last modified.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
709
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
710
        tree1 = self.make_branch_and_tree('t1')
711
        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.
712
        self._commit_sprout_rename_merge_converged(tree1, 'link')
3775.2.24 by Robert Collins
CommitBuilder.record_iter_changes handles changed-in-branch symlinks.
713
3775.2.33 by Robert Collins
Fix bug with merges of new files, increasing test coverage to ensure its kept fixed.
714
    def test_last_modified_revision_after_merge_new_dir_unchanged(self):
715
        # merge a new dir does not change the last modified.
716
        tree1 = self.make_branch_and_tree('t1')
6915.3.1 by Jelmer Vernooij
Skip tests that require versioned directories.
717
        if not tree1.has_versioned_directories():
718
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
719
                '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.
720
        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.
721
722
    def test_last_modified_revision_after_merge_new_file_unchanged(self):
723
        # merge a new file does not change the last modified.
724
        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.
725
        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.
726
727
    def test_last_modified_revision_after_merge_new_link_unchanged(self):
728
        # merge a new link does not change the last modified.
729
        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.
730
        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.
731
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
732
    def make_dir(self, name):
733
        self.build_tree([name + '/'])
734
735
    def make_file(self, name):
736
        self.build_tree([name])
737
738
    def make_link(self, name):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
739
        self.requireFeature(features.SymlinkFeature)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
740
        os.symlink('target', name)
741
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
742
    def make_reference(self, name):
6926.2.11 by Jelmer Vernooij
Don't rely on 1.9-rich-root.
743
        tree = self.make_branch_and_tree(name)
744
        if not tree.branch.repository._format.rich_root_data:
745
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
746
                'format does not support rich roots')
4183.5.2 by Robert Collins
Support tree-reference in record_iter_changes.
747
        tree.commit('foo')
748
        return tree
749
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
750
    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.
751
        tree = self.make_branch_and_tree('.')
752
        path = 'name'
753
        make_before(path)
2831.5.2 by Vincent Ladeuil
Review feedback.
754
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
755
        def change_kind():
6164.2.3 by Jelmer Vernooij
Use rmtree, since some vcses include control directories in every directory.
756
            if osutils.file_kind(path) == "directory":
757
                osutils.rmtree(path)
758
            else:
759
                osutils.delete_any(path)
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
760
            make_after(path)
2831.5.2 by Vincent Ladeuil
Review feedback.
761
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
762
        self._add_commit_change_check_changed(tree, (path, path), change_kind,
7143.15.2 by Jelmer Vernooij
Run autopep8.
763
                                              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.
764
765
    def test_last_modified_dir_file(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
766
        if not self.repository_format.supports_versioned_directories:
767
            # TODO(jelmer): Perhaps test this by creating a directory
768
            # with a file in it?
769
            raise tests.TestNotApplicable(
770
                'format does not support versioned directories')
6217.2.1 by Jelmer Vernooij
Allow tree implementations to not support kind changes.
771
        try:
772
            self._check_kind_change(self.make_dir, self.make_file,
7143.15.2 by Jelmer Vernooij
Run autopep8.
773
                                    expect_fs_hash=True)
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 file")
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_dir_link(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
780
        if not self.repository_format.supports_versioned_directories:
781
            # TODO(jelmer): Perhaps test this by creating a directory
782
            # with a file in it?
783
            raise tests.TestNotApplicable(
784
                'format does not support versioned directories')
6217.2.1 by Jelmer Vernooij
Allow tree implementations to not support kind changes.
785
        try:
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
786
            self._check_kind_change(self.make_dir, self.make_link)
6217.2.1 by Jelmer Vernooij
Allow tree implementations to not support kind changes.
787
        except errors.UnsupportedKindChange:
788
            raise tests.TestSkipped(
789
                "tree does not support changing entry kind from "
790
                "directory to link")
3775.2.25 by Robert Collins
CommitBuilder.record_iter_changes handles directories becoming files and links.
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_link_file(self):
3709.3.1 by Robert Collins
First cut - make it work - at updating the tree stat cache during commit.
793
        self._check_kind_change(self.make_link, self.make_file,
7143.15.2 by Jelmer Vernooij
Run autopep8.
794
                                expect_fs_hash=True)
3775.2.26 by Robert Collins
CommitBuilder.record_iter_changes handles links becomes directories and files.
795
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
796
    def test_last_modified_link_dir(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
797
        if not self.repository_format.supports_versioned_directories:
798
            # TODO(jelmer): Perhaps test this by creating a directory
799
            # with a file in it?
800
            raise tests.TestNotApplicable(
801
                'format does not support versioned directories')
802
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
803
        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.
804
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
805
    def test_last_modified_file_dir(self):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
806
        if not self.repository_format.supports_versioned_directories:
807
            # TODO(jelmer): Perhaps test this by creating a directory
808
            # with a file in it?
809
            raise tests.TestNotApplicable(
810
                'format does not support versioned directories')
811
6885.7.2 by Jelmer Vernooij
Simplify CommitBuilder tests, fix some tests for formats that don't support rename tracking.
812
        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.
813
2776.1.5 by Robert Collins
Add reasonably comprehensive tests for path last modified and per file graph behaviour.
814
    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.
815
        self._check_kind_change(self.make_file, self.make_link)
3775.2.28 by Robert Collins
Merge .dev.
816
3831.1.1 by John Arbash Meinel
Before allowing commit to succeed, verify the texts will be 'safe'.
817
    def test_get_commit_builder_with_invalid_revprops(self):
818
        branch = self.make_branch('.')
819
        branch.repository.lock_write()
820
        self.addCleanup(branch.repository.unlock)
821
        self.assertRaises(ValueError, branch.repository.get_commit_builder,
7143.15.2 by Jelmer Vernooij
Run autopep8.
822
                          branch, [], branch.get_config_stack(),
823
                          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'.
824
7490.74.2 by Jelmer Vernooij
Use surrogateescape in revprops.
825
    def test_get_commit_builder_with_surrogateescape(self):
7490.74.3 by Jelmer Vernooij
Fix tests.
826
        if not PY3:
827
            self.skipTest('python 2 does not have surrogateescape')
7490.74.2 by Jelmer Vernooij
Use surrogateescape in revprops.
828
        tree = self.make_branch_and_tree(".")
829
        with tree.lock_write():
830
            builder = tree.branch.get_commit_builder([], revprops={
831
                'invalid': u'property' + b'\xc0'.decode('utf-8', 'surrogateescape')})
832
            list(builder.record_iter_changes(tree, tree.last_revision(),
833
                                             tree.iter_changes(tree.basis_tree())))
834
            builder.finish_inventory()
835
            try:
836
                rev_id = builder.commit('foo bar blah')
837
            except NotImplementedError:
838
                raise tests.TestNotApplicable(
839
                    'Format does not support revision properties')
840
        rev = tree.branch.repository.get_revision(rev_id)
841
        self.assertEqual('foo bar blah', rev.message)
842
3831.1.1 by John Arbash Meinel
Before allowing commit to succeed, verify the texts will be 'safe'.
843
    def test_commit_builder_commit_with_invalid_message(self):
844
        branch = self.make_branch('.')
845
        branch.repository.lock_write()
846
        self.addCleanup(branch.repository.unlock)
847
        builder = branch.repository.get_commit_builder(branch, [],
7143.15.2 by Jelmer Vernooij
Run autopep8.
848
                                                       branch.get_config_stack())
3831.1.1 by John Arbash Meinel
Before allowing commit to succeed, verify the texts will be 'safe'.
849
        self.addCleanup(branch.repository.abort_write_group)
850
        self.assertRaises(ValueError, builder.commit,
7143.15.2 by Jelmer Vernooij
Run autopep8.
851
                          u'Invalid\r\ncommit message\r\n')
4595.4.2 by Robert Collins
Disable commit builders on stacked repositories.
852
5485.4.2 by Martin
Move guard to CommitBuilder.__init__ and test to bt.per_repository
853
    def test_non_ascii_str_committer_rejected(self):
854
        """Ensure an error is raised on a non-ascii byte string committer"""
855
        branch = self.make_branch('.')
856
        branch.repository.lock_write()
857
        self.addCleanup(branch.repository.unlock)
858
        self.assertRaises(UnicodeDecodeError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
859
                          branch.repository.get_commit_builder,
860
                          branch, [], branch.get_config_stack(),
861
                          committer=b"Erik B\xe5gfors <erik@example.com>")
5485.4.2 by Martin
Move guard to CommitBuilder.__init__ and test to bt.per_repository
862
4595.4.2 by Robert Collins
Disable commit builders on stacked repositories.
863
    def test_stacked_repositories_reject_commit_builder(self):
864
        # 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
865
        # broken if we aren't in a chk repository. So old repositories with
866
        # fallbacks refuse to hand out a commit builder.
4595.4.2 by Robert Collins
Disable commit builders on stacked repositories.
867
        repo_basis = self.make_repository('basis')
868
        branch = self.make_branch('local')
869
        repo_local = branch.repository
870
        try:
871
            repo_local.add_fallback_repository(repo_basis)
872
        except errors.UnstackableRepositoryFormat:
873
            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
874
        self.addCleanup(repo_local.lock_write().unlock)
875
        if not repo_local._format.supports_chks:
876
            self.assertRaises(errors.BzrError, repo_local.get_commit_builder,
7143.15.2 by Jelmer Vernooij
Run autopep8.
877
                              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
878
        else:
879
            builder = repo_local.get_commit_builder(branch, [],
6351.3.3 by Jelmer Vernooij
Convert more stuff to use config stacks.
880
                                                    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
881
            builder.abort()
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
882
883
    def test_committer_no_username(self):
884
        # Ensure that when no username is available but a committer is
885
        # supplied, commit works.
7344.1.1 by Martin
Fix tests that need whoami not to be set
886
        override_whoami(self)
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
887
        tree = self.make_branch_and_tree(".")
7206.6.1 by Jelmer Vernooij
Drop file_id from record_iter_changes return value.
888
        with tree.lock_write():
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
889
            # Make sure no username is available.
7336.2.1 by Martin
Split non-ini config methods to bedding
890
            self.assertRaises(errors.NoWhoami, tree.branch.get_commit_builder,
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
891
                              [])
892
            builder = tree.branch.get_commit_builder(
893
                [], committer='me@example.com')
894
            try:
895
                list(builder.record_iter_changes(tree, tree.last_revision(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
896
                                                 tree.iter_changes(tree.basis_tree())))
5050.18.1 by Aaron Bentley
CommitBuilder user committer, not username in revision-id.
897
                builder.finish_inventory()
898
            except:
899
                builder.abort()
900
                raise
901
            repo = tree.branch.repository
902
            repo.commit_write_group()