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