23
import bzrlib.bzrdir as bzrdir
22
from bzrlib import branch, bzrdir, errors, gpg, transactions, repository
24
23
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
25
from bzrlib.commit import commit
26
import bzrlib.errors as errors
24
from bzrlib.delta import TreeDelta
27
25
from bzrlib.errors import (FileExists,
30
28
UninitializableFormat,
34
31
from bzrlib.osutils import getcwd
35
32
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
36
33
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
37
34
from bzrlib.trace import mutter
38
import bzrlib.transactions as transactions
39
35
from bzrlib.transport import get_transport
40
36
from bzrlib.transport.http import HttpServer
41
37
from bzrlib.transport.memory import MemoryServer
101
97
tree = b2.repository.revision_tree('revision-1')
102
98
self.assertEqual(tree.get_file_text('foo-id'), 'hello')
100
def test_get_revision_delta(self):
101
tree_a = self.make_branch_and_tree('a')
102
self.build_tree(['a/foo'])
103
tree_a.add('foo', 'file1')
104
tree_a.commit('rev1', rev_id='rev1')
105
self.build_tree(['a/vla'])
106
tree_a.add('vla', 'file2')
107
tree_a.commit('rev2', rev_id='rev2')
109
delta = tree_a.branch.get_revision_delta(1)
110
self.assertIsInstance(delta, TreeDelta)
111
self.assertEqual([('foo', 'file1', 'file')], delta.added)
112
delta = tree_a.branch.get_revision_delta(2)
113
self.assertIsInstance(delta, TreeDelta)
114
self.assertEqual([('vla', 'file2', 'file')], delta.added)
104
116
def get_unbalanced_tree_pair(self):
105
117
"""Return two branches, a and b, with one file in a."""
106
118
get_transport(self.get_url()).mkdir('a')
227
239
branch = wt.branch
228
240
wt.commit("base", allow_pointless=True, rev_id='A')
229
241
from bzrlib.testament import Testament
230
strategy = bzrlib.gpg.LoopbackGPGStrategy(None)
242
strategy = gpg.LoopbackGPGStrategy(None)
231
243
branch.repository.sign_revision('A', strategy)
232
244
self.assertEqual(Testament.from_revision(branch.repository,
233
245
'A').as_short_text(),
237
249
wt = self.make_branch_and_tree('.')
238
250
branch = wt.branch
239
251
branch.repository.store_revision_signature(
240
bzrlib.gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
252
gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
241
253
self.assertRaises(errors.NoSuchRevision,
242
254
branch.repository.has_signature_for_revision_id,
249
261
wt = self.make_branch_and_tree('source')
250
262
wt.commit('A', allow_pointless=True, rev_id='A')
251
263
wt.branch.repository.sign_revision('A',
252
bzrlib.gpg.LoopbackGPGStrategy(None))
264
gpg.LoopbackGPGStrategy(None))
253
265
#FIXME: clone should work to urls,
254
266
# wt.clone should work to disks.
255
267
self.build_tree(['target/'])
308
320
self.assertEqual(repo.bzrdir.root_transport.base,
309
321
child_branch.repository.bzrdir.root_transport.base)
310
child_branch = bzrlib.branch.Branch.open(self.get_url('child'))
322
child_branch = branch.Branch.open(self.get_url('child'))
311
323
self.assertEqual(repo.bzrdir.root_transport.base,
312
324
child_branch.repository.bzrdir.root_transport.base)
316
328
text = tree.branch._format.get_format_description()
317
329
self.failUnless(len(text))
331
def test_check_branch_report_results(self):
332
"""Checking a branch produces results which can be printed"""
333
branch = self.make_branch('.')
334
result = branch.check()
335
# reports results through logging
336
result.report_results(verbose=True)
337
result.report_results(verbose=False)
339
def test_get_commit_builder(self):
340
self.assertIsInstance(self.make_branch(".").get_commit_builder([]),
341
repository.CommitBuilder)
320
344
class ChrootedTests(TestCaseWithBranch):
321
345
"""A support class that provides readonly urls outside the local namespace.
460
484
self.assertEqual(None, self.get_branch().get_push_location())
462
486
def test_get_push_location_exact(self):
463
from bzrlib.config import (branches_config_filename,
487
from bzrlib.config import (locations_config_filename,
464
488
ensure_config_dir_exists)
465
489
ensure_config_dir_exists()
466
fn = branches_config_filename()
490
fn = locations_config_filename()
467
491
print >> open(fn, 'wt'), ("[%s]\n"
468
492
"push_location=foo" %
469
493
self.get_branch().base[:-1])
470
494
self.assertEqual("foo", self.get_branch().get_push_location())
472
496
def test_set_push_location(self):
473
from bzrlib.config import (branches_config_filename,
497
from bzrlib.config import (locations_config_filename,
474
498
ensure_config_dir_exists)
475
499
ensure_config_dir_exists()
476
fn = branches_config_filename()
500
fn = locations_config_filename()
477
501
self.get_branch().set_push_location('foo')
478
502
self.assertFileEqual("[%s]\n"
479
503
"push_location = foo" % self.get_branch().base[:-1],
497
521
t = get_transport(self.get_url())
498
522
readonly_t = get_transport(self.get_readonly_url())
499
523
made_branch = self.make_branch('.')
500
self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
524
self.failUnless(isinstance(made_branch, branch.Branch))
502
526
# find it via bzrdir opening:
503
527
opened_control = bzrdir.BzrDir.open(readonly_t.base)
508
532
self.branch_format.__class__))
510
534
# find it via Branch.open
511
opened_branch = bzrlib.branch.Branch.open(readonly_t.base)
535
opened_branch = branch.Branch.open(readonly_t.base)
512
536
self.failUnless(isinstance(opened_branch, made_branch.__class__))
513
537
self.assertEqual(made_branch._format.__class__,
514
538
opened_branch._format.__class__)
518
542
except NotImplementedError:
520
544
self.assertEqual(self.branch_format,
521
bzrlib.branch.BranchFormat.find_format(opened_control))
545
branch.BranchFormat.find_format(opened_control))