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