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