1# Copyright (C) 2009 Canonical Ltd
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
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
16
17"""Tests for initializing a repository with external references."""
18
19
20from breezy import (
21    errors,
22    tests,
23    )
24from breezy.tests.per_repository_reference import (
25    TestCaseWithExternalReferenceRepository,
26    )
27
28
29class TestInitialize(TestCaseWithExternalReferenceRepository):
30
31    def initialize_and_check_on_transport(self, base, trans):
32        network_name = base.repository._format.network_name()
33        result = self.bzrdir_format.initialize_on_transport_ex(
34            trans, use_existing_dir=False, create_prefix=False,
35            stacked_on='../base', stack_on_pwd=base.base,
36            repo_format_name=network_name)
37        result_repo, a_controldir, require_stacking, repo_policy = result
38        self.addCleanup(result_repo.unlock)
39        self.assertEqual(1, len(result_repo._fallback_repositories))
40        return result_repo
41
42    def test_initialize_on_transport_ex(self):
43        base = self.make_branch('base')
44        trans = self.get_transport('stacked')
45        repo = self.initialize_and_check_on_transport(base, trans)
46        self.assertEqual(base.repository._format.network_name(),
47                         repo._format.network_name())
48
49    def test_remote_initialize_on_transport_ex(self):
50        # All formats can be initialized appropriately over bzr://
51        base = self.make_branch('base')
52        trans = self.make_smart_server('stacked')
53        repo = self.initialize_and_check_on_transport(base, trans)
54        network_name = base.repository._format.network_name()
55        self.assertEqual(network_name, repo._format.network_name())
56