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