1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006-2011 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
27
26
revision as _mod_revision,
29
28
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
from bzrlib.tests.blackbox import ExternalBase
29
from bzrlib.tests import TestCaseWithTransport
31
30
from bzrlib.tests import (
38
36
from bzrlib.workingtree import WorkingTree
41
class TestBranch(ExternalBase):
39
class TestBranch(TestCaseWithTransport):
43
41
def example_branch(self, path='.'):
44
42
tree = self.make_branch_and_tree(path)
174
172
target_stat = os.stat('target/file1')
175
173
self.assertEqual(source_stat, target_stat)
175
def test_branch_files_from(self):
176
source = self.make_branch_and_tree('source')
177
self.build_tree(['source/file1'])
179
source.commit('added file')
180
out, err = self.run_bzr('branch source target --files-from source')
181
self.failUnlessExists('target/file1')
183
def test_branch_files_from_hardlink(self):
184
self.requireFeature(HardlinkFeature)
185
source = self.make_branch_and_tree('source')
186
self.build_tree(['source/file1'])
188
source.commit('added file')
189
source.bzrdir.sprout('second')
190
out, err = self.run_bzr('branch source target --files-from second'
192
source_stat = os.stat('source/file1')
193
second_stat = os.stat('second/file1')
194
target_stat = os.stat('target/file1')
195
self.assertNotEqual(source_stat, target_stat)
196
self.assertEqual(second_stat, target_stat)
177
198
def test_branch_standalone(self):
178
199
shared_repo = self.make_repository('repo', shared=True)
179
200
self.example_branch('source')
247
268
self.run_bzr('checkout --lightweight a b')
248
269
self.assertLength(2, calls)
251
class TestBranchStacked(ExternalBase):
271
def test_branch_fetches_all_tags(self):
272
builder = self.make_branch_builder('source')
273
builder.build_commit(message="Rev 1", rev_id='rev-1')
274
builder.build_commit(message="Rev 2", rev_id='rev-2')
275
source = builder.get_branch()
276
source.tags.set_tag('tag-a', 'rev-2')
277
source.set_last_revision_info(1, 'rev-1')
278
# Now source has a tag not in its ancestry. Make a branch from it.
279
self.run_bzr('branch source new-branch')
280
new_branch = branch.Branch.open('new-branch')
281
# The tag is present, and so is its revision.
282
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
283
new_branch.repository.get_revision('rev-2')
286
class TestBranchStacked(TestCaseWithTransport):
252
287
"""Tests for branch --stacked"""
254
289
def assertRevisionInRepository(self, repo_path, revid):
379
class TestSmartServerBranching(ExternalBase):
414
class TestSmartServerBranching(TestCaseWithTransport):
381
416
def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
382
417
self.setup_smart_server_with_call_log()
391
426
# being too low. If rpc_count increases, more network roundtrips have
392
427
# become necessary for this use case. Please do not adjust this number
393
428
# upwards without agreement from bzr's network support maintainers.
394
self.assertLength(38, self.hpss_calls)
429
self.assertLength(36, self.hpss_calls)
396
431
def test_branch_from_trivial_branch_streaming_acceptance(self):
397
432
self.setup_smart_server_with_call_log()
406
441
# being too low. If rpc_count increases, more network roundtrips have
407
442
# become necessary for this use case. Please do not adjust this number
408
443
# upwards without agreement from bzr's network support maintainers.
409
self.assertLength(10, self.hpss_calls)
444
self.assertLength(9, self.hpss_calls)
411
446
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
412
447
self.setup_smart_server_with_call_log()
426
461
# being too low. If rpc_count increases, more network roundtrips have
427
462
# become necessary for this use case. Please do not adjust this number
428
463
# upwards without agreement from bzr's network support maintainers.
429
self.assertLength(15, self.hpss_calls)
464
self.assertLength(14, self.hpss_calls)
466
def test_branch_from_branch_with_tags(self):
467
self.setup_smart_server_with_call_log()
468
builder = self.make_branch_builder('source')
469
builder.build_commit(message="Rev 1", rev_id='rev-1')
470
builder.build_commit(message="Rev 2", rev_id='rev-2')
471
source = builder.get_branch()
472
source.tags.set_tag('tag-a', 'rev-2')
473
source.tags.set_tag('tag-missing', 'missing-rev')
474
source.set_last_revision_info(1, 'rev-1')
475
# Now source has a tag not in its ancestry. Make a branch from it.
476
self.reset_smart_call_log()
477
out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
478
# This figure represent the amount of work to perform this use case. It
479
# is entirely ok to reduce this number if a test fails due to rpc_count
480
# being too low. If rpc_count increases, more network roundtrips have
481
# become necessary for this use case. Please do not adjust this number
482
# upwards without agreement from bzr's network support maintainers.
483
self.assertLength(9, self.hpss_calls)
432
486
class TestRemoteBranch(TestCaseWithSFTPServer):