1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008 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
41
41
from bzrlib.osutils import getcwd
42
42
import bzrlib.revision
43
from bzrlib.symbol_versioning import deprecated_in
43
44
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
44
45
from bzrlib.tests.branch_implementations import TestCaseWithBranch
45
46
from bzrlib.tests.http_server import HttpServer
48
49
from bzrlib.transport.memory import MemoryServer
49
50
from bzrlib.upgrade import upgrade
50
51
from bzrlib.workingtree import WorkingTree
51
from bzrlib.symbol_versioning import (
56
54
class TestBranch(TestCaseWithBranch):
58
56
def test_create_tree_with_merge(self):
59
57
tree = self.create_tree_with_merge()
60
ancestry_graph = tree.branch.repository.get_revision_graph('rev-3')
61
self.assertEqual({'rev-1':(),
59
self.addCleanup(tree.unlock)
60
graph = tree.branch.repository.get_graph()
61
ancestry_graph = graph.get_parent_map(tree.branch.repository.all_revision_ids())
62
self.assertEqual({'rev-1':('null:',),
62
63
'rev-2':('rev-1', ),
63
64
'rev-1.1.1':('rev-1', ),
64
65
'rev-3':('rev-2', 'rev-1.1.1', ),
214
215
wt = self.make_branch_and_tree('.')
215
216
wt.set_parent_ids(['non:existent@rev--ision--0--2'],
216
217
allow_leftmost_as_ghost=True)
218
self.assertEqual(['non:existent@rev--ision--0--2'],
217
220
rev_id = wt.commit('commit against a ghost first parent.')
218
221
rev = wt.branch.repository.get_revision(rev_id)
219
222
self.assertEqual(rev.parent_ids, ['non:existent@rev--ision--0--2'])
302
305
self.assertEqual(repo.get_signature_text('A'),
303
306
d2.open_repository().get_signature_text('A'))
308
def test_missing_revisions(self):
309
t1 = self.make_branch_and_tree('b1')
310
rev1 = t1.commit('one')
311
t2 = t1.bzrdir.sprout('b2').open_workingtree()
312
rev2 = t1.commit('two')
313
rev3 = t1.commit('three')
315
self.assertEqual([rev2, rev3],
316
self.applyDeprecated(deprecated_in((1, 6, 0)),
317
t2.branch.missing_revisions, t1.branch))
320
self.applyDeprecated(deprecated_in((1, 6, 0)),
321
t2.branch.missing_revisions, t1.branch, stop_revision=1))
322
self.assertEqual([rev2],
323
self.applyDeprecated(deprecated_in((1, 6, 0)),
324
t2.branch.missing_revisions, t1.branch, stop_revision=2))
325
self.assertEqual([rev2, rev3],
326
self.applyDeprecated(deprecated_in((1, 6, 0)),
327
t2.branch.missing_revisions, t1.branch, stop_revision=3))
329
self.assertRaises(errors.NoSuchRevision,
330
self.applyDeprecated, deprecated_in((1, 6, 0)),
331
t2.branch.missing_revisions, t1.branch, stop_revision=4)
333
rev4 = t2.commit('four')
334
self.assertRaises(errors.DivergedBranches,
335
self.applyDeprecated, deprecated_in((1, 6, 0)),
336
t2.branch.missing_revisions, t1.branch)
305
338
def test_nicks(self):
306
339
"""Test explicit and implicit branch nicknames.
321
354
# Set the branch nick explicitly. This will ensure there's a branch
322
355
# config file in the branch.
323
356
branch.nick = "Aaron's branch"
324
branch.nick = "Aaron's branch"
325
357
if not isinstance(branch, remote.RemoteBranch):
326
controlfilename = branch.control_files.controlfilename
327
self.failUnless(t.has(t.relpath(controlfilename("branch.conf"))))
358
self.failUnless(branch._transport.has("branch.conf"))
328
359
# Because the nick has been set explicitly, the nick is now always
329
360
# "Aaron's branch", regardless of directory name.
330
361
self.assertEqual(branch.nick, "Aaron's branch")
368
399
text = tree.branch._format.get_format_description()
369
400
self.failUnless(len(text))
371
def test_check_branch_report_results(self):
372
"""Checking a branch produces results which can be printed"""
373
branch = self.make_branch('.')
374
result = branch.check()
375
# reports results through logging
376
result.report_results(verbose=True)
377
result.report_results(verbose=False)
379
402
def test_get_commit_builder(self):
380
403
branch = self.make_branch(".")
381
404
branch.lock_write()