13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21
from bzrlib import (
24
from bzrlib.errors import (
26
InvalidLineInBugsProperty,
28
from bzrlib.revision import NULL_REVISION
25
from bzrlib.branch import Branch
26
from bzrlib.errors import NoSuchRevision
27
from bzrlib.deprecated_graph import Graph
28
from bzrlib.revision import (find_present_ancestors,
30
from bzrlib.symbol_versioning import one_three
29
31
from bzrlib.tests import TestCase, TestCaseWithTransport
30
from bzrlib.tests.matchers import MatchesAncestry
32
from bzrlib.trace import mutter
33
from bzrlib.workingtree import WorkingTree
32
35
# We're allowed to test deprecated interfaces
33
36
warnings.filterwarnings('ignore',
58
61
tree1 = self.make_branch_and_tree("branch1", format=format)
61
64
tree1.commit("Commit one", rev_id="a@u-0-0")
62
65
tree1.commit("Commit two", rev_id="a@u-0-1")
63
66
tree1.commit("Commit three", rev_id="a@u-0-2")
65
tree2 = tree1.bzrdir.sprout("branch2").open_workingtree()
68
tree2 = tree1.bzrdir.clone("branch2").open_workingtree()
67
70
tree2.commit("Commit four", rev_id="b@u-0-3")
68
71
tree2.commit("Commit five", rev_id="b@u-0-4")
69
self.assertEqual(br2.last_revision(), 'b@u-0-4')
72
revisions_2 = br2.revision_history()
73
self.assertEquals(revisions_2[-1], 'b@u-0-4')
71
75
tree1.merge_from_branch(br2)
72
76
tree1.commit("Commit six", rev_id="a@u-0-3")
73
77
tree1.commit("Commit seven", rev_id="a@u-0-4")
74
78
tree2.commit("Commit eight", rev_id="b@u-0-5")
75
self.assertEqual(br2.last_revision(), 'b@u-0-5')
79
self.assertEquals(br2.revision_history()[-1], 'b@u-0-5')
77
81
tree1.merge_from_branch(br2)
78
82
tree1.commit("Commit nine", rev_id="a@u-0-5")
79
83
# DO NOT MERGE HERE - we WANT a GHOST.
82
graph = br1.repository.get_graph()
83
revhistory = list(graph.iter_lefthand_ancestry(br1.last_revision(),
84
[revision.NULL_REVISION]))
88
tree2.add_parent_tree_id(revhistory[4])
84
tree2.add_parent_tree_id(br1.revision_history()[4])
89
85
tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
111
107
('a@u-0-5', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
112
108
'b@u-0-3', 'b@u-0-4',
113
109
'b@u-0-5', 'a@u-0-5']),
114
('b@u-0-6', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-4',
110
('b@u-0-6', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2',
115
111
'b@u-0-3', 'b@u-0-4',
116
112
'b@u-0-5', 'b@u-0-6']),
124
120
if rev_id in br2_only and not branch is br2:
127
MatchesAncestry(branch.repository, rev_id))
122
mutter('ancestry of {%s}: %r',
123
rev_id, branch.repository.get_ancestry(rev_id))
124
result = sorted(branch.repository.get_ancestry(rev_id))
125
self.assertEquals(result, [None] + sorted(anc))
130
128
class TestIntermediateRevisions(TestCaseWithTransport):
144
142
wt2.merge_from_branch(self.br1)
145
143
wt2.commit("Commit fifteen", rev_id="b@u-0-10")
145
from bzrlib.revision import MultipleRevisionSources
146
self.sources = self.applyDeprecated(one_three,
147
MultipleRevisionSources, self.br1.repository,
148
152
class MockRevisionSource(object):
149
153
"""A RevisionSource that takes a pregenerated graph.
206
210
self.assertEqual('a', r.get_summary())
207
211
r.message = '\na\nb'
208
212
self.assertEqual('a', r.get_summary())
210
self.assertEqual('', r.get_summary())
212
def test_get_apparent_authors(self):
214
def test_get_apparent_author(self):
213
215
r = revision.Revision('1')
214
216
r.committer = 'A'
215
self.assertEqual(['A'], r.get_apparent_authors())
217
self.assertEqual('A', r.get_apparent_author())
216
218
r.properties['author'] = 'B'
217
self.assertEqual(['B'], r.get_apparent_authors())
218
r.properties['authors'] = 'C\nD'
219
self.assertEqual(['C', 'D'], r.get_apparent_authors())
221
def test_get_apparent_authors_no_committer(self):
222
r = revision.Revision('1')
223
self.assertEqual([], r.get_apparent_authors())
226
class TestRevisionBugs(TestCase):
227
"""Tests for getting the bugs that a revision is linked to."""
229
def test_no_bugs(self):
230
r = revision.Revision('1')
231
self.assertEqual([], list(r.iter_bugs()))
233
def test_some_bugs(self):
234
r = revision.Revision(
236
'bugs': bugtracker.encode_fixes_bug_urls(
237
['http://example.com/bugs/1',
238
'http://launchpad.net/bugs/1234'])})
240
[('http://example.com/bugs/1', bugtracker.FIXED),
241
('http://launchpad.net/bugs/1234', bugtracker.FIXED)],
244
def test_no_status(self):
245
r = revision.Revision(
246
'1', properties={'bugs': 'http://example.com/bugs/1'})
247
self.assertRaises(InvalidLineInBugsProperty, list, r.iter_bugs())
249
def test_too_much_information(self):
250
r = revision.Revision(
251
'1', properties={'bugs': 'http://example.com/bugs/1 fixed bar'})
252
self.assertRaises(InvalidLineInBugsProperty, list, r.iter_bugs())
254
def test_invalid_status(self):
255
r = revision.Revision(
256
'1', properties={'bugs': 'http://example.com/bugs/1 faxed'})
257
self.assertRaises(InvalidBugStatus, list, r.iter_bugs())
219
self.assertEqual('B', r.get_apparent_author())