1
# Copyright (C) 2006, 2007 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
24
from bzrlib.tag import (
26
_merge_tags_if_possible,
28
from bzrlib.tests import (
30
TestCaseWithTransport,
34
class TestTagSerialization(TestCase):
36
def test_tag_serialization(self):
37
"""Test the precise representation of tag dicts."""
38
# Don't change this after we commit to this format, as it checks
39
# that the format is stable and compatible across releases.
41
# This release stores them in bencode as a dictionary from name to
43
store = BasicTags(branch=None)
44
td = dict(stable='stable-revid', boring='boring-revid')
45
packed = store._serialize_tag_dict(td)
46
expected = r'd6:boring12:boring-revid6:stable12:stable-revide'
47
self.assertEqualDiff(packed, expected)
48
self.assertEqual(store._deserialize_tag_dict(packed), td)
51
class TestTagMerging(TestCaseWithTransport):
53
def make_knit_branch(self, relpath):
54
old_bdf = bzrdir.format_registry.make_bzrdir('knit')
55
return bzrdir.BzrDir.create_branch_convenience(relpath, format=old_bdf)
57
def make_branch_supporting_tags(self, relpath):
58
return self.make_branch(relpath, format='dirstate-tags')
60
def test_merge_not_possible(self):
61
# test merging between branches which do and don't support tags
62
old_branch = self.make_knit_branch('old')
63
new_branch = self.make_branch_supporting_tags('new')
64
# just to make sure this test is valid
65
self.assertFalse(old_branch.supports_tags(),
66
"%s is expected to not support tags but does" % old_branch)
67
self.assertTrue(new_branch.supports_tags(),
68
"%s is expected to support tags but does not" % new_branch)
69
# there are no tags in the old one, and we can merge from it into the
71
old_branch.tags.merge_to(new_branch.tags)
72
# we couldn't merge tags from the new branch to the old one, but as
73
# there are not any yet this isn't a problem
74
new_branch.tags.merge_to(old_branch.tags)
75
# but if there is a tag in the new one, we get a warning when trying
77
new_branch.tags.set_tag(u'\u2040tag', 'revid')
78
old_branch.tags.merge_to(new_branch.tags)
79
self.assertRaises(errors.TagsNotSupported,
80
new_branch.tags.merge_to, old_branch.tags)