~ubuntu-branches/debian/wheezy/bzr-fastimport/wheezy

« back to all changes in this revision

Viewing changes to tests/test_head_tracking.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-07-20 16:34:20 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110720163420-lmsnc1cgd94c20ev
Tags: 0.10.0+bzr324-1
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""Test tracking of heads"""
18
 
 
19
 
from cStringIO import StringIO
20
 
 
21
 
from bzrlib import tests
22
 
 
23
 
from bzrlib.plugins.fastimport import (
24
 
    commands,
25
 
    parser,
26
 
    )
27
 
from bzrlib.plugins.fastimport.cache_manager import CacheManager
28
 
 
29
 
 
30
 
# A sample input stream that only adds files to a branch
31
 
_SAMPLE_MAINLINE = \
32
 
"""blob
33
 
mark :1
34
 
data 9
35
 
Welcome!
36
 
commit refs/heads/master
37
 
mark :100
38
 
committer a <b@c> 1234798653 +0000
39
 
data 4
40
 
test
41
 
M 644 :1 doc/README.txt
42
 
blob
43
 
mark :2
44
 
data 17
45
 
Life
46
 
is
47
 
good ...
48
 
commit refs/heads/master
49
 
mark :101
50
 
committer a <b@c> 1234798653 +0000
51
 
data 8
52
 
test
53
 
ing
54
 
from :100
55
 
M 644 :2 NEWS
56
 
blob
57
 
mark :3
58
 
data 19
59
 
Welcome!
60
 
my friend
61
 
blob
62
 
mark :4
63
 
data 11
64
 
== Docs ==
65
 
commit refs/heads/master
66
 
mark :102
67
 
committer d <b@c> 1234798653 +0000
68
 
data 8
69
 
test
70
 
ing
71
 
from :101
72
 
M 644 :3 doc/README.txt
73
 
M 644 :4 doc/index.txt
74
 
"""
75
 
 
76
 
# A sample input stream that adds files to two branches
77
 
_SAMPLE_TWO_HEADS = \
78
 
"""blob
79
 
mark :1
80
 
data 9
81
 
Welcome!
82
 
commit refs/heads/master
83
 
mark :100
84
 
committer a <b@c> 1234798653 +0000
85
 
data 4
86
 
test
87
 
M 644 :1 doc/README.txt
88
 
blob
89
 
mark :2
90
 
data 17
91
 
Life
92
 
is
93
 
good ...
94
 
commit refs/heads/mybranch
95
 
mark :101
96
 
committer a <b@c> 1234798653 +0000
97
 
data 8
98
 
test
99
 
ing
100
 
from :100
101
 
M 644 :2 NEWS
102
 
blob
103
 
mark :3
104
 
data 19
105
 
Welcome!
106
 
my friend
107
 
blob
108
 
mark :4
109
 
data 11
110
 
== Docs ==
111
 
commit refs/heads/master
112
 
mark :102
113
 
committer d <b@c> 1234798653 +0000
114
 
data 8
115
 
test
116
 
ing
117
 
from :100
118
 
M 644 :3 doc/README.txt
119
 
M 644 :4 doc/index.txt
120
 
"""
121
 
 
122
 
# A sample input stream that adds files to two branches
123
 
_SAMPLE_TWO_BRANCHES_MERGED = \
124
 
"""blob
125
 
mark :1
126
 
data 9
127
 
Welcome!
128
 
commit refs/heads/master
129
 
mark :100
130
 
committer a <b@c> 1234798653 +0000
131
 
data 4
132
 
test
133
 
M 644 :1 doc/README.txt
134
 
blob
135
 
mark :2
136
 
data 17
137
 
Life
138
 
is
139
 
good ...
140
 
commit refs/heads/mybranch
141
 
mark :101
142
 
committer a <b@c> 1234798653 +0000
143
 
data 8
144
 
test
145
 
ing
146
 
from :100
147
 
M 644 :2 NEWS
148
 
blob
149
 
mark :3
150
 
data 19
151
 
Welcome!
152
 
my friend
153
 
blob
154
 
mark :4
155
 
data 11
156
 
== Docs ==
157
 
commit refs/heads/master
158
 
mark :102
159
 
committer d <b@c> 1234798653 +0000
160
 
data 8
161
 
test
162
 
ing
163
 
from :100
164
 
M 644 :3 doc/README.txt
165
 
M 644 :4 doc/index.txt
166
 
commit refs/heads/master
167
 
mark :103
168
 
committer d <b@c> 1234798653 +0000
169
 
data 8
170
 
test
171
 
ing
172
 
from :102
173
 
merge :101
174
 
D doc/index.txt
175
 
"""
176
 
 
177
 
# A sample input stream that contains a reset
178
 
_SAMPLE_RESET = \
179
 
"""blob
180
 
mark :1
181
 
data 9
182
 
Welcome!
183
 
commit refs/heads/master
184
 
mark :100
185
 
committer a <b@c> 1234798653 +0000
186
 
data 4
187
 
test
188
 
M 644 :1 doc/README.txt
189
 
reset refs/remotes/origin/master
190
 
from :100
191
 
"""
192
 
 
193
 
# A sample input stream that contains a reset and more commits
194
 
_SAMPLE_RESET_WITH_MORE_COMMITS = \
195
 
"""blob
196
 
mark :1
197
 
data 9
198
 
Welcome!
199
 
commit refs/heads/master
200
 
mark :100
201
 
committer a <b@c> 1234798653 +0000
202
 
data 4
203
 
test
204
 
M 644 :1 doc/README.txt
205
 
reset refs/remotes/origin/master
206
 
from :100
207
 
commit refs/remotes/origin/master
208
 
mark :101
209
 
committer d <b@c> 1234798653 +0000
210
 
data 8
211
 
test
212
 
ing
213
 
from :100
214
 
D doc/README.txt
215
 
"""
216
 
 
217
 
class TestHeadTracking(tests.TestCase):
218
 
 
219
 
    def assertHeads(self, input, expected):
220
 
        s = StringIO(input)
221
 
        p = parser.ImportParser(s)
222
 
        cm = CacheManager()
223
 
        for cmd in p.iter_commands():
224
 
            if isinstance(cmd, commands.CommitCommand):
225
 
                cm.track_heads(cmd)
226
 
                # eat the file commands
227
 
                list(cmd.file_iter())
228
 
            elif isinstance(cmd, commands.ResetCommand):
229
 
                if cmd.from_ is not None:
230
 
                    cm.track_heads_for_ref(cmd.ref, cmd.from_)
231
 
        self.assertEqual(cm.heads, expected)
232
 
 
233
 
    def test_mainline(self):
234
 
        self.assertHeads(_SAMPLE_MAINLINE, {
235
 
            ':102': set(['refs/heads/master']),
236
 
            })
237
 
 
238
 
    def test_two_heads(self):
239
 
        self.assertHeads(_SAMPLE_TWO_HEADS, {
240
 
            ':101': set(['refs/heads/mybranch']),
241
 
            ':102': set(['refs/heads/master']),
242
 
            })
243
 
 
244
 
    def test_two_branches_merged(self):
245
 
        self.assertHeads(_SAMPLE_TWO_BRANCHES_MERGED, {
246
 
            ':103': set(['refs/heads/master']),
247
 
            })
248
 
 
249
 
    def test_reset(self):
250
 
        self.assertHeads(_SAMPLE_RESET, {
251
 
            ':100': set(['refs/heads/master', 'refs/remotes/origin/master']),
252
 
            })
253
 
 
254
 
    def test_reset_with_more_commits(self):
255
 
        self.assertHeads(_SAMPLE_RESET_WITH_MORE_COMMITS, {
256
 
            ':101': set(['refs/remotes/origin/master']),
257
 
            })