~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_interbranch/__init__.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
27
27
 
28
28
from bzrlib import (
29
29
    branchbuilder,
30
 
    memorytree,
31
30
    )
32
31
from bzrlib.branch import (
33
32
                           GenericInterBranch,
34
33
                           InterBranch,
35
34
                           )
36
 
from bzrlib.bzrdir import (
37
 
    BzrDirFormat,
38
 
    BzrDirMetaFormat1,
39
 
    )
40
35
from bzrlib.tests import (
41
36
    TestCaseWithTransport,
42
37
    multiply_tests,
81
76
class TestCaseWithInterBranch(TestCaseWithTransport):
82
77
 
83
78
    def make_from_branch(self, relpath):
84
 
        repo = self.make_repository(relpath, format=self.branch_format_from._matchingbzrdir)
85
 
        return self.branch_format_from.initialize(repo.bzrdir)
 
79
        return self.make_branch(relpath, format=self.branch_format_from._matchingbzrdir)
86
80
 
87
81
    def make_from_branch_and_memory_tree(self, relpath):
88
82
        """Create a branch on the default transport and a MemoryTree for it."""
89
 
        b = self.make_from_branch(relpath)
90
 
        return memorytree.MemoryTree.create_on_branch(b)
 
83
        self.assertEqual(
 
84
            self.branch_format_from._matchingbzrdir.get_branch_format(),
 
85
            self.branch_format_from)
 
86
        return self.make_branch_and_memory_tree(
 
87
            relpath, format=self.branch_format_from._matchingbzrdir)
91
88
 
92
89
    def make_from_branch_and_tree(self, relpath):
93
90
        """Create a branch on the default transport and a working tree for it."""
 
91
        self.assertEqual(
 
92
            self.branch_format_from._matchingbzrdir.get_branch_format(),
 
93
            self.branch_format_from)
94
94
        return self.make_branch_and_tree(relpath,
95
95
            format=self.branch_format_from._matchingbzrdir)
96
96
 
97
97
    def make_from_branch_builder(self, relpath):
 
98
        self.assertEqual(
 
99
            self.branch_format_from._matchingbzrdir.get_branch_format(),
 
100
            self.branch_format_from)
98
101
        return branchbuilder.BranchBuilder(self.get_transport(relpath),
99
102
            format=self.branch_format_from._matchingbzrdir)
100
103
 
101
104
    def make_to_branch(self, relpath):
102
 
        repo = self.make_repository(relpath, format=self.branch_format_to._matchingbzrdir)
103
 
        return self.branch_format_to.initialize(repo.bzrdir)
 
105
        self.assertEqual(
 
106
            self.branch_format_to._matchingbzrdir.get_branch_format(),
 
107
            self.branch_format_to)
 
108
        return self.make_branch(relpath, format=self.branch_format_to._matchingbzrdir)
104
109
 
105
110
    def make_to_branch_and_memory_tree(self, relpath):
106
111
        """Create a branch on the default transport and a MemoryTree for it."""
107
 
        b = self.make_to_branch(relpath)
108
 
        return memorytree.MemoryTree.create_on_branch(b)
 
112
        self.assertEqual(
 
113
            self.branch_format_to._matchingbzrdir.get_branch_format(),
 
114
            self.branch_format_to)
 
115
        return self.make_branch_and_memory_tree(
 
116
            relpath, format=self.branch_format_to._matchingbzrdir)
109
117
 
110
118
    def make_to_branch_and_tree(self, relpath):
111
119
        """Create a branch on the default transport and a working tree for it."""
 
120
        self.assertEqual(
 
121
            self.branch_format_to._matchingbzrdir.get_branch_format(),
 
122
            self.branch_format_to)
112
123
        return self.make_branch_and_tree(relpath,
113
124
            format=self.branch_format_to._matchingbzrdir)
114
125
 
 
126
    def _sprout(self, origdir, to_url, format):
 
127
        if format.supports_workingtrees:
 
128
            newbranch = self.make_branch(to_url, format=format)
 
129
        else:
 
130
            newbranch = self.make_branch(to_url+".branch", format=format)
 
131
        origbranch = origdir.open_branch()
 
132
        newbranch.repository.fetch(origbranch.repository)
 
133
        origbranch.copy_content_into(newbranch)
 
134
        if format.supports_workingtrees:
 
135
            wt = newbranch.bzrdir.create_workingtree()
 
136
        else:
 
137
            wt = newbranch.create_checkout(to_url, lightweight=True)
 
138
        return wt
 
139
 
115
140
    def sprout_to(self, origdir, to_url):
116
141
        """Sprout a bzrdir, using to_format for the new branch."""
117
 
        newbranch = self.make_to_branch(to_url)
118
 
        origbranch = origdir.open_branch()
119
 
        newbranch.repository.fetch(origbranch.repository)
120
 
        origbranch.copy_content_into(newbranch)
121
 
        newbranch.bzrdir.create_workingtree()
122
 
        return newbranch.bzrdir
 
142
        wt = self._sprout(origdir, to_url, self.branch_format_to._matchingbzrdir)
 
143
        self.assertEqual(wt.branch._format, self.branch_format_to)
 
144
        return wt.bzrdir
123
145
 
124
146
    def sprout_from(self, origdir, to_url):
125
147
        """Sprout a bzrdir, using from_format for the new bzrdir."""
126
 
        newbranch = self.make_from_branch(to_url)
127
 
        origbranch = origdir.open_branch()
128
 
        newbranch.repository.fetch(origbranch.repository)
129
 
        origbranch.copy_content_into(newbranch)
130
 
        newbranch.bzrdir.create_workingtree()
131
 
        return newbranch.bzrdir
 
148
        wt = self._sprout(origdir, to_url,
 
149
            self.branch_format_from._matchingbzrdir)
 
150
        self.assertEqual(wt.branch._format, self.branch_format_from)
 
151
        return wt.bzrdir
132
152
 
133
153
 
134
154
class StubWithFormat(object):