1
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2007, 2009-2012, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
58
57
store = self.make_branch_supporting_tags('a').tags
59
58
store.set_tag("foo", "myoldrevid")
60
59
store.rename_revisions({"myoldrevid": "mynewrevid"})
61
self.assertEquals({"foo": "mynewrevid"}, store.get_tag_dict())
60
self.assertEqual({"foo": "mynewrevid"}, store.get_tag_dict())
63
62
def test_unknown_ignored(self):
64
63
store = self.make_branch_supporting_tags('a').tags
65
64
store.set_tag("foo", "myoldrevid")
66
65
store.rename_revisions({"anotherrevid": "mynewrevid"})
67
self.assertEquals({"foo": "myoldrevid"}, store.get_tag_dict())
66
self.assertEqual({"foo": "myoldrevid"}, store.get_tag_dict())
70
69
class TestTagMerging(TestCaseWithTransport):
72
71
def make_knit_branch(self, relpath):
73
old_bdf = bzrdir.format_registry.make_bzrdir('knit')
74
return bzrdir.BzrDir.create_branch_convenience(relpath, format=old_bdf)
72
old_bdf = controldir.format_registry.make_bzrdir('knit')
73
return controldir.ControlDir.create_branch_convenience(relpath, format=old_bdf)
76
75
def make_branch_supporting_tags(self, relpath):
77
76
return self.make_branch(relpath, format='dirstate-tags')
110
109
self.assertRaises(errors.NoSuchTag, a.tags.lookup_tag, 'tag-2')
111
110
# conflicting merge
112
111
a.tags.set_tag('tag-2', 'z')
113
conflicts = a.tags.merge_to(b.tags)
114
self.assertEqual(conflicts, [('tag-2', 'z', 'y')])
112
updates, conflicts = a.tags.merge_to(b.tags)
113
self.assertEqual({}, updates)
114
self.assertEqual(list(conflicts), [('tag-2', 'z', 'y')])
115
115
self.assertEqual('y', b.tags.lookup_tag('tag-2'))
116
116
# overwrite conflicts
117
conflicts = a.tags.merge_to(b.tags, overwrite=True)
118
self.assertEqual(conflicts, [])
117
updates, conflicts = a.tags.merge_to(b.tags, overwrite=True)
118
self.assertEqual(list(conflicts), [])
119
self.assertEqual({u'tag-2': 'z'}, updates)
119
120
self.assertEqual('z', b.tags.lookup_tag('tag-2'))
122
123
class TestTagsInCheckouts(TestCaseWithTransport):
124
"""Tests for how tags are synchronised between the master and child branch
124
128
def test_update_tag_into_checkout(self):
125
129
# checkouts are directly connected to the tags of their master branch:
129
133
child = self.make_branch('child')
130
134
child.bind(master)
131
135
child.tags.set_tag('foo', 'rev-1')
132
self.assertEquals('rev-1', master.tags.lookup_tag('foo'))
136
self.assertEqual('rev-1', master.tags.lookup_tag('foo'))
133
137
# deleting a tag updates the master too
134
138
child.tags.delete_tag('foo')
135
139
self.assertRaises(errors.NoSuchTag,
140
144
master = self.make_branch('master')
141
145
master.tags.set_tag('foo', 'rev-1')
142
146
co_tree = master.create_checkout('checkout')
143
self.assertEquals('rev-1',
147
self.assertEqual('rev-1',
144
148
co_tree.branch.tags.lookup_tag('foo'))
146
150
def test_update_updates_tags(self):
151
155
child.bind(master)
153
157
# after an update, the child has all the master's tags
154
self.assertEquals('rev-1', child.tags.lookup_tag('foo'))
158
self.assertEqual('rev-1', child.tags.lookup_tag('foo'))
155
159
# add another tag and update again
156
160
master.tags.set_tag('tag2', 'target2')
158
self.assertEquals('target2', child.tags.lookup_tag('tag2'))
162
self.assertEqual('target2', child.tags.lookup_tag('tag2'))
160
164
def test_tag_deletion_from_master_to_bound(self):
161
165
master = self.make_branch('master')
166
170
# and deletion of tags should also propagate
167
171
master.tags.delete_tag('foo')
168
raise KnownFailure("tag deletion does not propagate: "
172
self.knownFailure("tag deletion does not propagate: "
169
173
"https://bugs.launchpad.net/bzr/+bug/138802")
170
174
self.assertRaises(errors.NoSuchTag,
171
175
child.tags.lookup_tag, 'foo')