/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
1
# Copyright (C) 2009 Canonical Ltd
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for interface conformance of 'WorkingTree.annotate_iter'"""
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
20
21
22
class TestAnnotateIter(TestCaseWithWorkingTree):
23
24
    def make_single_rev_tree(self):
25
        builder = self.make_branch_builder('branch')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
26
        revid = builder.build_snapshot(None, [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
27
            ('add', ('', 'TREE_ROOT', 'directory', None)),
28
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
29
            ])
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
30
        b = builder.get_branch()
31
        tree = b.create_checkout('tree', lightweight=True)
32
        tree.lock_read()
33
        self.addCleanup(tree.unlock)
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
34
        return tree, revid
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
35
36
    def test_annotate_same_as_parent(self):
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
37
        tree, revid = self.make_single_rev_tree()
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
38
        annotations = tree.annotate_iter('file')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
39
        self.assertEqual([(revid, 'initial content\n')],
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
40
                         annotations)
41
42
    def test_annotate_mod_from_parent(self):
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
43
        tree, revid = self.make_single_rev_tree()
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
44
        self.build_tree_contents([('tree/file',
45
                                   'initial content\nnew content\n')])
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
46
        annotations = tree.annotate_iter('file')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
47
        self.assertEqual([(revid, 'initial content\n'),
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
48
                          ('current:', 'new content\n'),
49
                         ], annotations)
50
51
    def test_annotate_merge_parents(self):
52
        builder = self.make_branch_builder('branch')
53
        builder.start_series()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
54
        revid1 = builder.build_snapshot(None, [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
55
            ('add', ('', 'TREE_ROOT', 'directory', None)),
56
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
57
            ])
58
        revid2 = builder.build_snapshot([revid1], [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
59
            ('modify', ('file-id', 'initial content\ncontent in 2\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
60
            ])
61
        revid3 = builder.build_snapshot([revid1], [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
62
            ('modify', ('file-id', 'initial content\ncontent in 3\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
63
            ])
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
64
        builder.finish_series()
65
        b = builder.get_branch()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
66
        tree = b.create_checkout('tree', revision_id=revid2, lightweight=True)
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
67
        tree.lock_write()
68
        self.addCleanup(tree.unlock)
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
69
        tree.set_parent_ids([revid2, revid3])
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
70
        self.build_tree_contents([('tree/file',
71
                                   'initial content\ncontent in 2\n'
72
                                   'content in 3\nnew content\n')])
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
73
        annotations = tree.annotate_iter('file')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
74
        self.assertEqual([(revid1, 'initial content\n'),
75
                          (revid2, 'content in 2\n'),
76
                          (revid3, 'content in 3\n'),
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
77
                          ('current:', 'new content\n'),
78
                         ], annotations)
79
80
    def test_annotate_merge_parent_no_file(self):
81
        builder = self.make_branch_builder('branch')
82
        builder.start_series()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
83
        revid1 = builder.build_snapshot(None, [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
84
            ('add', ('', 'TREE_ROOT', 'directory', None)),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
85
            ])
86
        revid2 = builder.build_snapshot([revid1], [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
87
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
88
            ])
89
        revid3 = builder.build_snapshot([revid1], [])
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
90
        builder.finish_series()
91
        b = builder.get_branch()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
92
        tree = b.create_checkout('tree', revision_id=revid2, lightweight=True)
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
93
        tree.lock_write()
94
        self.addCleanup(tree.unlock)
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
95
        tree.set_parent_ids([revid2, revid3])
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
96
        self.build_tree_contents([('tree/file',
97
                                   'initial content\nnew content\n')])
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
98
        annotations = tree.annotate_iter('file')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
99
        self.assertEqual([(revid2, 'initial content\n'),
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
100
                          ('current:', 'new content\n'),
101
                         ], annotations)
102
103
    def test_annotate_merge_parent_was_directory(self):
104
        builder = self.make_branch_builder('branch')
105
        builder.start_series()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
106
        revid1 = builder.build_snapshot(None, [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
107
            ('add', ('', 'TREE_ROOT', 'directory', None)),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
108
            ])
109
        revid2 = builder.build_snapshot([revid1], [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
110
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
111
            ])
112
        revid3 = builder.build_snapshot([revid1], [
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
113
            ('add', ('a_dir', 'file-id', 'directory', None)),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
114
            ])
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
115
        builder.finish_series()
116
        b = builder.get_branch()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
117
        tree = b.create_checkout('tree', revision_id=revid2, lightweight=True)
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
118
        tree.lock_write()
119
        self.addCleanup(tree.unlock)
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
120
        tree.set_parent_ids([revid2, revid3])
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
121
        self.build_tree_contents([('tree/file',
122
                                   'initial content\nnew content\n')])
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
123
        annotations = tree.annotate_iter('file')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
124
        self.assertEqual([(revid2, 'initial content\n'),
4454.3.68 by John Arbash Meinel
Add some tests that we can handle doing annotations even when
125
                          ('current:', 'new content\n'),
126
                         ], annotations)
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
127
128
    def test_annotate_same_as_merge_parent(self):
129
        builder = self.make_branch_builder('branch')
130
        builder.start_series()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
131
        revid1 = builder.build_snapshot(None, [
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
132
            ('add', ('', 'TREE_ROOT', 'directory', None)),
133
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
134
            ])
135
        revid2 = builder.build_snapshot([revid1], [
136
            ])
137
        revid3 = builder.build_snapshot([revid1], [
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
138
            ('modify', ('file-id', 'initial content\ncontent in 3\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
139
            ])
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
140
        builder.finish_series()
141
        b = builder.get_branch()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
142
        tree = b.create_checkout('tree', revision_id=revid2, lightweight=True)
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
143
        tree.lock_write()
144
        self.addCleanup(tree.unlock)
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
145
        tree.set_parent_ids([revid2, revid3])
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
146
        self.build_tree_contents([('tree/file',
147
                                   'initial content\ncontent in 3\n')])
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
148
        annotations = tree.annotate_iter('file')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
149
        self.assertEqual([(revid1, 'initial content\n'),
150
                          (revid3, 'content in 3\n'),
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
151
                         ], annotations)
152
153
    def test_annotate_same_as_merge_parent_supersedes(self):
154
        builder = self.make_branch_builder('branch')
155
        builder.start_series()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
156
        revid1 = builder.build_snapshot(None, [
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
157
            ('add', ('', 'TREE_ROOT', 'directory', None)),
158
            ('add', ('file', 'file-id', 'file', 'initial content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
159
            ])
160
        revid2 = builder.build_snapshot([revid1], [
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
161
            ('modify', ('file-id', 'initial content\nnew content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
162
            ])
163
        revid3 = builder.build_snapshot([revid2], [
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
164
            ('modify', ('file-id', 'initial content\ncontent in 3\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
165
            ])
166
        revid4 = builder.build_snapshot([revid3], [
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
167
            ('modify', ('file-id', 'initial content\nnew content\n')),
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
168
            ])
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
169
        # In this case, the content locally is the same as content in basis
170
        # tree, but the merge revision states that *it* should win
171
        builder.finish_series()
172
        b = builder.get_branch()
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
173
        tree = b.create_checkout('tree', revision_id=revid2, lightweight=True)
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
174
        tree.lock_write()
175
        self.addCleanup(tree.unlock)
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
176
        tree.set_parent_ids([revid2, revid4])
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
177
        annotations = tree.annotate_iter('file')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
178
        self.assertEqual([(revid1, 'initial content\n'),
179
                          (revid4, 'new content\n'),
4454.3.69 by John Arbash Meinel
Add a couple more annotate-after-merge tests for WT.
180
                         ], annotations)
181