1
# Copyright (C) 2009 Canonical Ltd
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.
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.
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
17
"""Test tracking of heads"""
19
from cStringIO import StringIO
21
from bzrlib import tests
23
from bzrlib.plugins.fastimport import (
27
from bzrlib.plugins.fastimport.cache_manager import CacheManager
30
# A sample input stream that only adds files to a branch
36
commit refs/heads/master
38
committer a <b@c> 1234798653 +0000
41
M 644 :1 doc/README.txt
48
commit refs/heads/master
50
committer a <b@c> 1234798653 +0000
65
commit refs/heads/master
67
committer d <b@c> 1234798653 +0000
72
M 644 :3 doc/README.txt
73
M 644 :4 doc/index.txt
76
# A sample input stream that adds files to two branches
82
commit refs/heads/master
84
committer a <b@c> 1234798653 +0000
87
M 644 :1 doc/README.txt
94
commit refs/heads/mybranch
96
committer a <b@c> 1234798653 +0000
111
commit refs/heads/master
113
committer d <b@c> 1234798653 +0000
118
M 644 :3 doc/README.txt
119
M 644 :4 doc/index.txt
122
# A sample input stream that adds files to two branches
123
_SAMPLE_TWO_BRANCHES_MERGED = \
128
commit refs/heads/master
130
committer a <b@c> 1234798653 +0000
133
M 644 :1 doc/README.txt
140
commit refs/heads/mybranch
142
committer a <b@c> 1234798653 +0000
157
commit refs/heads/master
159
committer d <b@c> 1234798653 +0000
164
M 644 :3 doc/README.txt
165
M 644 :4 doc/index.txt
166
commit refs/heads/master
168
committer d <b@c> 1234798653 +0000
177
# A sample input stream that contains a reset
183
commit refs/heads/master
185
committer a <b@c> 1234798653 +0000
188
M 644 :1 doc/README.txt
189
reset refs/remotes/origin/master
193
# A sample input stream that contains a reset and more commits
194
_SAMPLE_RESET_WITH_MORE_COMMITS = \
199
commit refs/heads/master
201
committer a <b@c> 1234798653 +0000
204
M 644 :1 doc/README.txt
205
reset refs/remotes/origin/master
207
commit refs/remotes/origin/master
209
committer d <b@c> 1234798653 +0000
217
class TestHeadTracking(tests.TestCase):
219
def assertHeads(self, input, expected):
221
p = parser.ImportParser(s)
223
for cmd in p.iter_commands():
224
if isinstance(cmd, commands.CommitCommand):
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)
233
def test_mainline(self):
234
self.assertHeads(_SAMPLE_MAINLINE, {
235
':102': set(['refs/heads/master']),
238
def test_two_heads(self):
239
self.assertHeads(_SAMPLE_TWO_HEADS, {
240
':101': set(['refs/heads/mybranch']),
241
':102': set(['refs/heads/master']),
244
def test_two_branches_merged(self):
245
self.assertHeads(_SAMPLE_TWO_BRANCHES_MERGED, {
246
':103': set(['refs/heads/master']),
249
def test_reset(self):
250
self.assertHeads(_SAMPLE_RESET, {
251
':100': set(['refs/heads/master', 'refs/remotes/origin/master']),
254
def test_reset_with_more_commits(self):
255
self.assertHeads(_SAMPLE_RESET_WITH_MORE_COMMITS, {
256
':101': set(['refs/remotes/origin/master']),