/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
905 by Martin Pool
- merge aaron's append_multiple.patch
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
905 by Martin Pool
- merge aaron's append_multiple.patch
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
905 by Martin Pool
- merge aaron's append_multiple.patch
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
905 by Martin Pool
- merge aaron's append_multiple.patch
16
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
17
"""Tests for branch implementations - tests a branch format."""
18
6538.1.31 by Aaron Bentley
Support foreign branches.
19
import contextlib
6538.1.2 by Aaron Bentley
Migrate tests to per_branch, support RemoteBranch.
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import (
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
22
    branch as _mod_branch,
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
23
    controldir,
5345.1.19 by Vincent Ladeuil
Cleanup bt.per_branch.test_branch.
24
    config,
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
25
    delta as _mod_delta,
1878.1.3 by John Arbash Meinel
some test cleanups
26
    errors,
6754.8.9 by Jelmer Vernooij
Fix more tests.
27
    lock,
4273.1.8 by Aaron Bentley
Handle references in push, pull, merge.
28
    merge,
6182.1.2 by Jelmer Vernooij
Fix branch test.
29
    osutils,
1878.1.3 by John Arbash Meinel
some test cleanups
30
    urlutils,
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
31
    transform,
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
32
    transport,
1878.1.3 by John Arbash Meinel
some test cleanups
33
    repository,
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
34
    revision,
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
35
    shelf,
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
36
    tests,
6883.8.1 by Jelmer Vernooij
Add Branch.create_memorytree.
37
    tree as _mod_tree,
1878.1.3 by John Arbash Meinel
some test cleanups
38
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
39
from breezy.bzr import (
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
40
    remote,
6670.4.3 by Jelmer Vernooij
Fix more imports.
41
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
42
from breezy.tests import (
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
43
    per_branch,
44
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
45
from breezy.tests.http_server import HttpServer
46
from breezy.transport import memory
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
47
48
49
class TestTestCaseWithBranch(per_branch.TestCaseWithBranch):
3834.5.2 by John Arbash Meinel
Track down the various BranchFormats that weren't setting the branch format as part of the _matchingbzrdir format.
50
51
    def test_branch_format_matches_bzrdir_branch_format(self):
52
        bzrdir_branch_format = self.bzrdir_format.get_branch_format()
6747.2.3 by Jelmer Vernooij
Fix formatting.
53
        self.assertIs(
7143.15.2 by Jelmer Vernooij
Run autopep8.
54
            self.branch_format.__class__,
55
            bzrdir_branch_format.__class__)
3834.5.2 by John Arbash Meinel
Track down the various BranchFormats that weren't setting the branch format as part of the _matchingbzrdir format.
56
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
57
    def test_make_branch_gets_expected_format(self):
58
        branch = self.make_branch('.')
6747.2.3 by Jelmer Vernooij
Fix formatting.
59
        self.assertIs(
7143.15.2 by Jelmer Vernooij
Run autopep8.
60
            self.branch_format.__class__,
61
            branch._format.__class__)
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
62
3834.5.2 by John Arbash Meinel
Track down the various BranchFormats that weren't setting the branch format as part of the _matchingbzrdir format.
63
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
64
class TestBranch(per_branch.TestCaseWithBranch):
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
65
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
66
    def test_create_tree_with_merge(self):
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
67
        tree, revmap = self.create_tree_with_merge()
3287.6.9 by Robert Collins
One last use of deprecated methods.
68
        tree.lock_read()
69
        self.addCleanup(tree.unlock)
70
        graph = tree.branch.repository.get_graph()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
71
        ancestry_graph = graph.get_parent_map(
72
            tree.branch.repository.all_revision_ids())
6973.6.2 by Jelmer Vernooij
Fix more tests.
73
        self.assertEqual({revmap['1']: (b'null:',),
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
74
                          revmap['2']: (revmap['1'], ),
75
                          revmap['1.1.1']: (revmap['1'], ),
76
                          revmap['3']: (revmap['2'], revmap['1.1.1'], ),
77
                          }, ancestry_graph)
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
78
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
79
    def test_revision_ids_are_utf8(self):
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
80
        wt = self.make_branch_and_tree('tree')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
81
        rev1 = wt.commit('f')
82
        rev2 = wt.commit('f')
83
        rev3 = wt.commit('f')
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
84
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
85
        br = self.get_branch()
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
86
        br.fetch(wt.branch)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
87
        br.generate_revision_history(rev3)
88
        for revision_id in [rev3, rev2, rev1]:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
89
            self.assertIsInstance(revision_id, bytes)
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
90
        last = br.last_revision()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
91
        self.assertEqual(rev3, last)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
92
        self.assertIsInstance(last, bytes)
2249.5.19 by John Arbash Meinel
Track through the new Branch6 code, and make sure revision ids are utf8
93
        revno, last = br.last_revision_info()
94
        self.assertEqual(3, revno)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
95
        self.assertEqual(rev3, last)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
96
        self.assertIsInstance(last, bytes)
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
97
1260 by Martin Pool
- some updates for fetch/update function
98
    def test_fetch_revisions(self):
99
        """Test fetch-revision operation."""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
100
        wt = self.make_branch_and_tree('b1')
101
        b1 = wt.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
102
        self.build_tree_contents([('b1/foo', b'hello')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
103
        wt.add(['foo'])
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
104
        rev1 = wt.commit('lala!', allow_pointless=False)
1260 by Martin Pool
- some updates for fetch/update function
105
2381.1.3 by Robert Collins
Review feedback.
106
        b2 = self.make_branch('b2')
7455.2.1 by Jelmer Vernooij
Return a FetchResult object from Repository.fetch / Branch.fetch.
107
        result = b2.fetch(b1)
108
        self.assertIsInstance(result, repository.FetchResult)
1260 by Martin Pool
- some updates for fetch/update function
109
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
110
        rev = b2.repository.get_revision(rev1)
111
        tree = b2.repository.revision_tree(rev1)
3015.2.1 by Robert Collins
Lock correctness in branch implementation tests.
112
        tree.lock_read()
113
        self.addCleanup(tree.unlock)
6973.6.1 by Jelmer Vernooij
More bees.
114
        self.assertEqual(tree.get_file_text('foo'), b'hello')
1260 by Martin Pool
- some updates for fetch/update function
115
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
116
    def get_unbalanced_tree_pair(self):
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
117
        """Return two branches, a and b, with one file in a."""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
118
        tree_a = self.make_branch_and_tree('a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
119
        self.build_tree_contents([('a/b', b'b')])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
120
        tree_a.add('b')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
121
        tree_a.commit("silly commit")
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
122
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
123
        tree_b = self.make_branch_and_tree('b')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
124
        return tree_a, tree_b
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
125
126
    def get_balanced_branch_pair(self):
127
        """Returns br_a, br_b as with one commit in a, and b has a's stores."""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
128
        tree_a, tree_b = self.get_unbalanced_tree_pair()
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
129
        tree_b.branch.repository.fetch(tree_a.branch.repository)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
130
        return tree_a, tree_b
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
131
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
132
    def test_clone_partial(self):
1393.1.23 by Martin Pool
- fix cloning of part of a branch
133
        """Copy only part of the history of a branch."""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
134
        # TODO: RBC 20060208 test with a revision not on revision-history.
135
        #       what should that behaviour be ? Emailed the list.
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
136
        # First, make a branch with two commits.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
137
        wt_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
138
        self.build_tree(['a/one'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
139
        wt_a.add(['one'])
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
140
        rev1 = wt_a.commit('commit one')
2381.1.3 by Robert Collins
Review feedback.
141
        self.build_tree(['a/two'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
142
        wt_a.add(['two'])
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
143
        wt_a.commit('commit two')
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
144
        # Now make a copy of the repository.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
145
        repo_b = self.make_repository('b')
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
146
        wt_a.branch.repository.copy_content_into(repo_b)
147
        # wt_a might be a lightweight checkout, so get a hold of the actual
148
        # branch (because you can't do a partial clone of a lightweight
149
        # checkout).
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
150
        branch = wt_a.branch.controldir.open_branch()
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
151
        # Then make a branch where the new repository is, but specify a revision
152
        # ID.  The new branch's history will stop at the specified revision.
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
153
        br_b = branch.clone(repo_b.controldir, revision_id=rev1)
154
        self.assertEqual(rev1, br_b.last_revision())
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
155
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
156
    def get_parented_branch(self):
157
        wt_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
158
        self.build_tree(['a/one'])
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
159
        wt_a.add(['one'])
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
160
        rev1 = wt_a.commit('commit one')
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
161
7143.15.2 by Jelmer Vernooij
Run autopep8.
162
        branch_b = wt_a.branch.controldir.sprout(
163
            'b', revision_id=rev1).open_branch()
7141.8.7 by Jelmer Vernooij
Fix tests.
164
        self.assertEqual(
7441.1.1 by Jelmer Vernooij
Add strip_segment_parameters function.
165
            urlutils.strip_segment_parameters(wt_a.branch.user_url),
166
            urlutils.strip_segment_parameters(branch_b.get_parent()))
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
167
        return branch_b
168
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
169
    def test_clone_branch_nickname(self):
170
        # test the nick name is preserved always
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
171
        raise tests.TestSkipped('XXX branch cloning is not yet tested.')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
172
173
    def test_clone_branch_parent(self):
174
        # test the parent is preserved always
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
175
        branch_b = self.get_parented_branch()
176
        repo_c = self.make_repository('c')
177
        branch_b.repository.copy_content_into(repo_c)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
178
        branch_c = branch_b.clone(repo_c.controldir)
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
179
        self.assertNotEqual(None, branch_c.get_parent())
180
        self.assertEqual(branch_b.get_parent(), branch_c.get_parent())
181
182
        # We can also set a specific parent, and it should be honored
5560.2.1 by Vincent Ladeuil
Fix the remaining references to http://bazaar-vcs.org (except the explicitly historical ones).
183
        random_parent = 'http://example.com/path/to/branch'
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
184
        branch_b.set_parent(random_parent)
185
        repo_d = self.make_repository('d')
186
        branch_b.repository.copy_content_into(repo_d)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
187
        branch_d = branch_b.clone(repo_d.controldir)
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
188
        self.assertEqual(random_parent, branch_d.get_parent())
189
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
190
    def test_submit_branch(self):
191
        """Submit location can be queried and set"""
192
        branch = self.make_branch('branch')
193
        self.assertEqual(branch.get_submit_branch(), None)
194
        branch.set_submit_branch('sftp://example.com')
195
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.com')
196
        branch.set_submit_branch('sftp://example.net')
197
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.net')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
198
1551.12.44 by Aaron Bentley
Add (set|get)_public_branch
199
    def test_public_branch(self):
200
        """public location can be queried and set"""
201
        branch = self.make_branch('branch')
202
        self.assertEqual(branch.get_public_branch(), None)
203
        branch.set_public_branch('sftp://example.com')
204
        self.assertEqual(branch.get_public_branch(), 'sftp://example.com')
205
        branch.set_public_branch('sftp://example.net')
206
        self.assertEqual(branch.get_public_branch(), 'sftp://example.net')
207
        branch.set_public_branch(None)
208
        self.assertEqual(branch.get_public_branch(), None)
209
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
210
    def test_record_initial_ghost(self):
211
        """Branches should support having ghosts."""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
212
        wt = self.make_branch_and_tree('.')
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
213
        if not wt.branch.repository._format.supports_ghosts:
214
            raise tests.TestNotApplicable("repository format does not "
7143.15.2 by Jelmer Vernooij
Run autopep8.
215
                                          "support ghosts")
6973.6.2 by Jelmer Vernooij
Fix more tests.
216
        wt.set_parent_ids([b'non:existent@rev--ision--0--2'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
217
                          allow_leftmost_as_ghost=True)
6973.6.2 by Jelmer Vernooij
Fix more tests.
218
        self.assertEqual([b'non:existent@rev--ision--0--2'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
219
                         wt.get_parent_ids())
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
220
        rev_id = wt.commit('commit against a ghost first parent.')
221
        rev = wt.branch.repository.get_revision(rev_id)
6973.7.5 by Jelmer Vernooij
s/file/open.
222
        self.assertEqual(rev.parent_ids, [b'non:existent@rev--ision--0--2'])
1092.2.25 by Robert Collins
support ghosts in commits
223
        # parent_sha1s is not populated now, WTF. rbc 20051003
224
        self.assertEqual(len(rev.parent_sha1s), 0)
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
225
226
    def test_record_two_ghosts(self):
227
        """Recording with all ghosts works."""
228
        wt = self.make_branch_and_tree('.')
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
229
        if not wt.branch.repository._format.supports_ghosts:
230
            raise tests.TestNotApplicable("repository format does not "
7143.15.2 by Jelmer Vernooij
Run autopep8.
231
                                          "support ghosts")
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
232
        wt.set_parent_ids([
7143.15.2 by Jelmer Vernooij
Run autopep8.
233
            b'foo@azkhazan-123123-abcabc',
234
            b'wibble@fofof--20050401--1928390812',
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
235
            ],
236
            allow_leftmost_as_ghost=True)
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
237
        rev_id = wt.commit("commit from ghost base with one merge")
238
        # the revision should have been committed with two parents
239
        rev = wt.branch.repository.get_revision(rev_id)
6973.6.2 by Jelmer Vernooij
Fix more tests.
240
        self.assertEqual([b'foo@azkhazan-123123-abcabc',
7143.15.2 by Jelmer Vernooij
Run autopep8.
241
                          b'wibble@fofof--20050401--1928390812'],
242
                         rev.parent_ids)
1092.2.25 by Robert Collins
support ghosts in commits
243
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
244
    def test_bad_revision(self):
1534.4.28 by Robert Collins
first cut at merge from integration.
245
        self.assertRaises(errors.InvalidRevisionId,
246
                          self.get_branch().repository.get_revision,
247
                          None)
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
248
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
249
    def test_nicks_bzr(self):
250
        """Test the behaviour of branch nicks specific to bzr branches.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
251
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
252
        Nicknames are implicitly the name of the branch's directory, unless an
253
        explicit nickname is set.  That is, an explicit nickname always
254
        overrides the implicit one.
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
255
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
256
        """
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
257
        t = self.get_transport()
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
258
        branch = self.make_branch('bzr.dev')
7490.49.2 by Jelmer Vernooij
Move more tests.
259
        if not branch.repository._format.supports_storing_branch_nick:
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
260
            raise tests.TestNotApplicable("not a bzr branch format")
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
261
        # The nick will be 'bzr.dev', because there is no explicit nick set.
1185.35.11 by Aaron Bentley
Added support for branch nicks
262
        self.assertEqual(branch.nick, 'bzr.dev')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
263
        # Move the branch to a different directory, 'bzr.ab'.  Now that branch
264
        # will report its nick as 'bzr.ab'.
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
265
        t.move('bzr.dev', 'bzr.ab')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
266
        branch = _mod_branch.Branch.open(self.get_url('bzr.ab'))
1185.35.11 by Aaron Bentley
Added support for branch nicks
267
        self.assertEqual(branch.nick, 'bzr.ab')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
268
        # Set the branch nick explicitly.  This will ensure there's a branch
269
        # config file in the branch.
270
        branch.nick = "Aaron's branch"
2018.5.129 by Robert Collins
Branch implementations test test_set_get_parent should not depend on local urls : the test can be valid for any url namespace. Change it to be valid in that manner. (Robert Collins, Andrew Bennetts)
271
        if not isinstance(branch, remote.RemoteBranch):
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
272
            self.assertTrue(branch._transport.has("branch.conf"))
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
273
        # Because the nick has been set explicitly, the nick is now always
274
        # "Aaron's branch", regardless of directory name.
1185.35.11 by Aaron Bentley
Added support for branch nicks
275
        self.assertEqual(branch.nick, "Aaron's branch")
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
276
        t.move('bzr.ab', 'integration')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
277
        branch = _mod_branch.Branch.open(self.get_url('integration'))
1185.35.11 by Aaron Bentley
Added support for branch nicks
278
        self.assertEqual(branch.nick, "Aaron's branch")
1185.35.12 by Aaron Bentley
Got writes of existing tree configs working.
279
        branch.nick = u"\u1234"
280
        self.assertEqual(branch.nick, u"\u1234")
1185.35.11 by Aaron Bentley
Added support for branch nicks
281
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
282
    def test_nicks(self):
283
        """Test explicit and implicit branch nicknames.
284
285
        A nickname is always available, whether set explicitly or not.
286
        """
287
        t = self.get_transport()
288
        branch = self.make_branch('bzr.dev')
289
        # An implicit nick name is set; what it is exactly depends on the
290
        # format.
7479.2.1 by Jelmer Vernooij
Drop python2 support.
291
        self.assertIsInstance(branch.nick, str)
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
292
        # Set the branch nick explicitly.
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
293
        branch.nick = u"Aaron's branch"
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
294
        # Because the nick has been set explicitly, the nick is now always
295
        # "Aaron's branch".
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
296
        self.assertEqual(branch.nick, u"Aaron's branch")
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
297
        branch.nick = u"\u1234"
298
        self.assertEqual(branch.nick, u"\u1234")
299
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
300
    def test_commit_nicks(self):
301
        """Nicknames are committed to the revision"""
302
        wt = self.make_branch_and_tree('bzr.dev')
303
        branch = wt.branch
304
        branch.nick = "My happy branch"
305
        wt.commit('My commit respect da nick.')
306
        committed = branch.repository.get_revision(branch.last_revision())
6820.1.1 by Jelmer Vernooij
add RepositoryFormat.supports_storing_branch_nick.
307
        if branch.repository._format.supports_storing_branch_nick:
308
            self.assertEqual(committed.properties["branch-nick"],
309
                             "My happy branch")
310
        else:
311
            self.assertNotIn("branch-nick", committed.properties)
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
312
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
313
    def test_create_colocated(self):
314
        try:
315
            repo = self.make_repository('.', shared=True)
316
        except errors.IncompatibleFormat:
317
            return
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
318
        if repo.controldir._format.colocated_branches:
6437.21.9 by Jelmer Vernooij
Some fixes.
319
            raise tests.TestNotApplicable(
320
                "control dir does not support colocated branches")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
321
        self.assertEqual(0, len(repo.controldir.list_branches()))
6437.21.7 by Jelmer Vernooij
Fix remaining tests.
322
        if not self.bzrdir_format.colocated_branches:
323
            raise tests.TestNotApplicable("control dir format does not support "
7143.15.2 by Jelmer Vernooij
Run autopep8.
324
                                          "colocated branches")
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
325
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
326
            child_branch1 = self.branch_format.initialize(repo.controldir,
327
                                                          name='branch1')
6437.21.9 by Jelmer Vernooij
Some fixes.
328
        except errors.UninitializableFormat:
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
329
            # branch references are not default init'able and
330
            # not all bzrdirs support colocated branches.
331
            return
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
332
        self.assertEqual(1, len(repo.controldir.list_branches()))
333
        self.branch_format.initialize(repo.controldir, name='branch2')
334
        self.assertEqual(2, len(repo.controldir.list_branches()))
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
335
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
336
    def test_create_append_revisions_only(self):
337
        try:
338
            repo = self.make_repository('.', shared=True)
339
        except errors.IncompatibleFormat:
340
            return
341
        for val in (True, False):
342
            try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
343
                branch = self.branch_format.initialize(repo.controldir,
7143.15.2 by Jelmer Vernooij
Run autopep8.
344
                                                       append_revisions_only=True)
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
345
            except (errors.UninitializableFormat, errors.UpgradeRequired):
346
                # branch references are not default init'able and
347
                # not all branches support append_revisions_only
348
                return
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
349
            self.assertEqual(True, branch.get_append_revisions_only())
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
350
            repo.controldir.destroy_branch()
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
351
6123.9.14 by Jelmer Vernooij
Fix RemoteBranch.get_append_revisions_only().
352
    def test_get_set_append_revisions_only(self):
353
        branch = self.make_branch('.')
354
        if branch._format.supports_set_append_revisions_only():
355
            branch.set_append_revisions_only(True)
356
            self.assertTrue(branch.get_append_revisions_only())
357
            branch.set_append_revisions_only(False)
358
            self.assertFalse(branch.get_append_revisions_only())
359
        else:
360
            self.assertRaises(errors.UpgradeRequired,
7143.15.2 by Jelmer Vernooij
Run autopep8.
361
                              branch.set_append_revisions_only, True)
6123.9.14 by Jelmer Vernooij
Fix RemoteBranch.get_append_revisions_only().
362
            self.assertFalse(branch.get_append_revisions_only())
363
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
364
    def test_create_open_branch_uses_repository(self):
365
        try:
366
            repo = self.make_repository('.', shared=True)
367
        except errors.IncompatibleFormat:
6162.5.1 by Jelmer Vernooij
Skip test if control dir format is not initializable.
368
            raise tests.TestNotApplicable("requires shared repository support")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
369
        child_transport = repo.controldir.root_transport.clone('child')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
370
        child_transport.mkdir('.')
6162.3.1 by Jelmer Vernooij
Skip a few tests for uninitializable formats.
371
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
372
            child_dir = self.bzrdir_format.initialize_on_transport(
373
                child_transport)
6162.3.1 by Jelmer Vernooij
Skip a few tests for uninitializable formats.
374
        except errors.UninitializableFormat:
7143.15.2 by Jelmer Vernooij
Run autopep8.
375
            raise tests.TestNotApplicable(
376
                "control dir format not initializable")
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
377
        try:
378
            child_branch = self.branch_format.initialize(child_dir)
379
        except errors.UninitializableFormat:
380
            # branch references are not default init'able.
381
            return
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
382
        self.assertEqual(repo.controldir.root_transport.base,
383
                         child_branch.repository.controldir.root_transport.base)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
384
        child_branch = _mod_branch.Branch.open(self.get_url('child'))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
385
        self.assertEqual(repo.controldir.root_transport.base,
386
                         child_branch.repository.controldir.root_transport.base)
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
387
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
388
    def test_format_description(self):
389
        tree = self.make_branch_and_tree('tree')
390
        text = tree.branch._format.get_format_description()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
391
        self.assertTrue(len(text))
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
392
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
393
    def test_get_commit_builder(self):
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
394
        branch = self.make_branch(".")
395
        branch.lock_write()
396
        builder = branch.get_commit_builder([])
397
        self.assertIsInstance(builder, repository.CommitBuilder)
398
        branch.repository.commit_write_group()
399
        branch.unlock()
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
400
1792.1.1 by Robert Collins
Factor out revision-history synthesis to make it reusable as Branch.generate_revision_history.
401
    def test_generate_revision_history(self):
402
        """Create a fake revision history easily."""
403
        tree = self.make_branch_and_tree('.')
404
        rev1 = tree.commit('foo')
6165.4.6 by Jelmer Vernooij
Avoid more uses of revision_history.
405
        tree.lock_write()
406
        self.addCleanup(tree.unlock)
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
407
        graph = tree.branch.repository.get_graph()
6165.4.16 by Jelmer Vernooij
Don't provide Branch.iter_reverse_revision_history.
408
        orig_history = list(
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
409
            graph.iter_lefthand_ancestry(
410
                tree.branch.last_revision(), [revision.NULL_REVISION]))
1792.1.1 by Robert Collins
Factor out revision-history synthesis to make it reusable as Branch.generate_revision_history.
411
        rev2 = tree.commit('bar', allow_pointless=True)
412
        tree.branch.generate_revision_history(rev1)
6165.4.16 by Jelmer Vernooij
Don't provide Branch.iter_reverse_revision_history.
413
        self.assertEqual(orig_history, list(
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
414
            graph.iter_lefthand_ancestry(
415
                tree.branch.last_revision(), [revision.NULL_REVISION])))
1792.1.1 by Robert Collins
Factor out revision-history synthesis to make it reusable as Branch.generate_revision_history.
416
1836.3.1 by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION.
417
    def test_generate_revision_history_NULL_REVISION(self):
418
        tree = self.make_branch_and_tree('.')
419
        rev1 = tree.commit('foo')
6165.4.6 by Jelmer Vernooij
Avoid more uses of revision_history.
420
        tree.lock_write()
421
        self.addCleanup(tree.unlock)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
422
        tree.branch.generate_revision_history(revision.NULL_REVISION)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
423
        self.assertEqual(revision.NULL_REVISION, tree.branch.last_revision())
1836.3.1 by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION.
424
1551.8.6 by Aaron Bentley
Rename test
425
    def test_create_checkout(self):
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
426
        tree_a = self.make_branch_and_tree('a')
427
        branch_a = tree_a.branch
1551.8.5 by Aaron Bentley
Change name to create_checkout
428
        checkout_b = branch_a.create_checkout('b')
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
429
        self.assertEqual(b'null:', checkout_b.last_revision())
6876.1.1 by Jelmer Vernooij
Allow InterBranch to not implement lossless fetch.
430
        try:
431
            rev1 = checkout_b.commit('rev1')
432
        except errors.NoRoundtrippingSupport:
433
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
434
                'roundtripping between %r and %r not supported' %
435
                (checkout_b.branch, checkout_b.branch.get_master_branch()))
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
436
        self.assertEqual(rev1, branch_a.last_revision())
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
437
        self.assertNotEqual(checkout_b.branch.base, branch_a.base)
438
1551.8.5 by Aaron Bentley
Change name to create_checkout
439
        checkout_c = branch_a.create_checkout('c', lightweight=True)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
440
        self.assertEqual(rev1, checkout_c.last_revision())
441
        rev2 = checkout_c.commit('rev2')
442
        self.assertEqual(rev2, branch_a.last_revision())
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
443
        self.assertEqual(checkout_c.branch.base, branch_a.base)
444
1551.8.5 by Aaron Bentley
Change name to create_checkout
445
        checkout_d = branch_a.create_checkout('d', lightweight=True)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
446
        self.assertEqual(rev2, checkout_d.last_revision())
1551.8.5 by Aaron Bentley
Change name to create_checkout
447
        checkout_e = branch_a.create_checkout('e')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
448
        self.assertEqual(rev2, checkout_e.last_revision())
1425 by Robert Collins
merge from Aaron - unbreaks open_containing and the fetch progress bar
449
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
450
    def test_create_anonymous_lightweight_checkout(self):
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
451
        """A lightweight checkout from a readonly branch should succeed."""
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
452
        tree_a = self.make_branch_and_tree('a')
453
        rev_id = tree_a.commit('put some content in the branch')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
454
        # open the branch via a readonly transport
6217.3.1 by Jelmer Vernooij
Skip tests against formats that don't support readonly modifier.
455
        url = self.get_readonly_url(urlutils.basename(tree_a.branch.base))
456
        t = transport.get_transport_from_url(url)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
457
        if not tree_a.branch.controldir._format.supports_transport(t):
6217.3.1 by Jelmer Vernooij
Skip tests against formats that don't support readonly modifier.
458
            raise tests.TestNotApplicable("format does not support transport")
459
        source_branch = _mod_branch.Branch.open(url)
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
460
        # sanity check that the test will be valid
461
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
7143.15.2 by Jelmer Vernooij
Run autopep8.
462
                          source_branch.lock_write)
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
463
        checkout = source_branch.create_checkout('c', lightweight=True)
464
        self.assertEqual(rev_id, checkout.last_revision())
465
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
466
    def test_create_anonymous_heavyweight_checkout(self):
467
        """A regular checkout from a readonly branch should succeed."""
468
        tree_a = self.make_branch_and_tree('a')
469
        rev_id = tree_a.commit('put some content in the branch')
2018.5.95 by Andrew Bennetts
Add a Transport.is_readonly remote call, let {Branch,Repository}.lock_write remote call return UnlockableTransport, and miscellaneous test fixes.
470
        # open the branch via a readonly transport
6182.1.16 by Jelmer Vernooij
Merge lp:bzr
471
        url = self.get_readonly_url(
472
            osutils.basename(tree_a.branch.base.rstrip('/')))
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
473
        t = transport.get_transport_from_url(url)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
474
        if not tree_a.branch.controldir._format.supports_transport(t):
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
475
            raise tests.TestNotApplicable("format does not support transport")
476
        source_branch = _mod_branch.Branch.open(url)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
477
        # sanity check that the test will be valid
478
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
7143.15.2 by Jelmer Vernooij
Run autopep8.
479
                          source_branch.lock_write)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
480
        checkout = source_branch.create_checkout('c')
481
        self.assertEqual(rev_id, checkout.last_revision())
482
5672.1.1 by Andrew Bennetts
Refactor some of FetchSpecFactory into new Branch.heads_to_fetch method so that branch implementations like looms can override it.
483
    def test_heads_to_fetch(self):
484
        # heads_to_fetch is a method that returns a collection of revids that
485
        # need to be fetched to copy this branch into another repo.  At a
486
        # minimum this will include the tip.
487
        # (In native formats, this is the tip + tags, but other formats may
488
        # have other revs needed)
489
        tree = self.make_branch_and_tree('a')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
490
        tree.commit('first commit')
491
        rev2 = tree.commit('second commit')
5672.1.1 by Andrew Bennetts
Refactor some of FetchSpecFactory into new Branch.heads_to_fetch method so that branch implementations like looms can override it.
492
        must_fetch, should_fetch = tree.branch.heads_to_fetch()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
493
        self.assertTrue(rev2 in must_fetch)
5672.1.1 by Andrew Bennetts
Refactor some of FetchSpecFactory into new Branch.heads_to_fetch method so that branch implementations like looms can override it.
494
495
    def test_heads_to_fetch_not_null_revision(self):
496
        # NULL_REVISION does not appear in the result of heads_to_fetch, even
497
        # for an empty branch.
498
        tree = self.make_branch_and_tree('a')
499
        must_fetch, should_fetch = tree.branch.heads_to_fetch()
500
        self.assertFalse(revision.NULL_REVISION in must_fetch)
501
        self.assertFalse(revision.NULL_REVISION in should_fetch)
502
6883.8.1 by Jelmer Vernooij
Add Branch.create_memorytree.
503
    def test_create_memorytree(self):
504
        tree = self.make_branch_and_tree('a')
505
        self.assertIsInstance(tree.branch.create_memorytree(), _mod_tree.Tree)
506
1551.8.4 by Aaron Bentley
Tweak import style
507
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
508
class TestBranchFormat(per_branch.TestCaseWithBranch):
4032.3.1 by Robert Collins
Add a BranchFormat.network_name() method as preparation for creating branches via RPC calls.
509
510
    def test_branch_format_network_name(self):
511
        br = self.make_branch('.')
512
        format = br._format
513
        network_name = format.network_name()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
514
        self.assertIsInstance(network_name, bytes)
4032.3.1 by Robert Collins
Add a BranchFormat.network_name() method as preparation for creating branches via RPC calls.
515
        # We want to test that the network_name matches the actual format on
516
        # disk. For local branches that means that using network_name as a key
517
        # in the registry gives back the same format. For remote branches we
518
        # check that the network_name of the RemoteBranchFormat we have locally
519
        # matches the actual format present on disk.
520
        if isinstance(format, remote.RemoteBranchFormat):
521
            br._ensure_real()
522
            real_branch = br._real_branch
523
            self.assertEqual(real_branch._format.network_name(), network_name)
524
        else:
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
525
            registry = _mod_branch.network_format_registry
4032.3.1 by Robert Collins
Add a BranchFormat.network_name() method as preparation for creating branches via RPC calls.
526
            looked_up_format = registry.get(network_name)
527
            self.assertEqual(format.__class__, looked_up_format.__class__)
528
6449.4.2 by Jelmer Vernooij
Fix test name.
529
    def test_get_config_calls(self):
6155.2.2 by Vincent Ladeuil
Add a smoke test as suggested in review.
530
        # Smoke test that all branch succeed getting a config
531
        br = self.make_branch('.')
532
        br.get_config()
533
        br.get_config_stack()
534
4032.3.1 by Robert Collins
Add a BranchFormat.network_name() method as preparation for creating branches via RPC calls.
535
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
536
class ChrootedTests(per_branch.TestCaseWithBranch):
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
537
    """A support class that provides readonly urls outside the local namespace.
538
539
    This is done by checking if self.transport_server is a MemoryServer. if it
540
    is then we are chrooted already, if it is not then an HttpServer is used
541
    for readonly urls.
542
    """
543
544
    def setUp(self):
545
        super(ChrootedTests, self).setUp()
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
546
        if not self.vfs_transport_factory == memory.MemoryServer:
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
547
            self.transport_readonly_server = HttpServer
1425 by Robert Collins
merge from Aaron - unbreaks open_containing and the fetch progress bar
548
1185.12.18 by Aaron Bentley
Fixed error handling when NotBranch on HTTP
549
    def test_open_containing(self):
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
550
        self.assertRaises(errors.NotBranchError,
551
                          _mod_branch.Branch.open_containing,
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
552
                          self.get_readonly_url(''))
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
553
        self.assertRaises(errors.NotBranchError,
554
                          _mod_branch.Branch.open_containing,
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
555
                          self.get_readonly_url('g/p/q'))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
556
        branch = self.make_branch('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
557
        if not branch.controldir._format.supports_transport(
7143.15.2 by Jelmer Vernooij
Run autopep8.
558
                transport.get_transport_from_url(self.get_readonly_url('.'))):
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
559
            raise tests.TestNotApplicable("format does not support transport")
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
560
        branch, relpath = _mod_branch.Branch.open_containing(
561
            self.get_readonly_url(''))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
562
        self.assertEqual('', relpath)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
563
        branch, relpath = _mod_branch.Branch.open_containing(
564
            self.get_readonly_url('g/p/q'))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
565
        self.assertEqual('g/p/q', relpath)
2929.3.21 by Vincent Ladeuil
Merge bzr.dev, resolve conflicts.
566
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
567
568
class InstrumentedTransaction(object):
569
570
    def finish(self):
571
        self.calls.append('finish')
572
573
    def __init__(self):
574
        self.calls = []
575
576
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
577
class TestDecorator(object):
578
579
    def __init__(self):
580
        self._calls = []
581
582
    def lock_read(self):
583
        self._calls.append('lr')
6754.8.9 by Jelmer Vernooij
Fix more tests.
584
        return lock.LogicalLockResult(self.unlock)
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
585
586
    def lock_write(self):
587
        self._calls.append('lw')
6754.8.9 by Jelmer Vernooij
Fix more tests.
588
        return lock.LogicalLockResult(self.unlock)
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
589
590
    def unlock(self):
591
        self._calls.append('ul')
592
593
    def do_with_read(self):
6754.8.9 by Jelmer Vernooij
Fix more tests.
594
        with self.lock_read():
595
            return 1
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
596
597
    def except_with_read(self):
6754.8.9 by Jelmer Vernooij
Fix more tests.
598
        with self.lock_read():
599
            raise RuntimeError
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
600
601
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
602
class TestBranchPushLocations(per_branch.TestCaseWithBranch):
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
603
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
604
    def test_get_push_location_unset(self):
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
605
        self.assertEqual(None, self.get_branch().get_push_location())
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
606
607
    def test_get_push_location_exact(self):
5345.1.19 by Vincent Ladeuil
Cleanup bt.per_branch.test_branch.
608
        b = self.get_branch()
5345.1.26 by Vincent Ladeuil
Merge lockable-config-files into remove-gratuitous-ensure-config-dir-exist-calls resolving conflicts
609
        config.LocationConfig.from_string(
5345.1.25 by Vincent Ladeuil
Move the '_save' parameter from '__init__' to 'from_bytes', fix fallouts.
610
            '[%s]\npush_location=foo\n' % (b.base,), b.base, save=True)
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
611
        self.assertEqual("foo", self.get_branch().get_push_location())
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
612
613
    def test_set_push_location(self):
1878.1.3 by John Arbash Meinel
some test cleanups
614
        branch = self.get_branch()
615
        branch.set_push_location('foo')
2230.3.3 by Aaron Bentley
Add more config testing
616
        self.assertEqual('foo', branch.get_push_location())
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
617
618
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
619
class TestChildSubmitFormats(per_branch.TestCaseWithBranch):
4382.3.1 by Jelmer Vernooij
Add Branch.get_child_submit_format(), so particular Branch implementations
620
621
    def test_get_child_submit_format_default(self):
6104.2.4 by Jelmer Vernooij
Allow get_child_submit_format to return a string.
622
        submit_format = self.get_branch().get_child_submit_format()
623
        self.assertTrue(submit_format is None or
7018.3.2 by Jelmer Vernooij
Fix some git tests.
624
                        isinstance(submit_format, str))
4382.3.1 by Jelmer Vernooij
Add Branch.get_child_submit_format(), so particular Branch implementations
625
626
    def test_get_child_submit_format(self):
627
        branch = self.get_branch()
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
628
        branch.get_config_stack().set('child_submit_format', '10')
4382.3.1 by Jelmer Vernooij
Add Branch.get_child_submit_format(), so particular Branch implementations
629
        branch = self.get_branch()
630
        self.assertEqual('10', branch.get_child_submit_format())
631
632
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
633
class TestFormat(per_branch.TestCaseWithBranch):
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
634
    """Tests for the format itself."""
635
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
636
    def test_get_reference(self):
637
        """get_reference on all regular branches should return None."""
638
        if not self.branch_format.is_supported():
639
            # unsupported formats are not loopback testable
640
            # because the default open will not open them and
641
            # they may not be initializable.
642
            return
6883.19.1 by Jelmer Vernooij
Allow default branch to be a branch reference.
643
        made_controldir = self.make_controldir('.')
644
        made_controldir.create_repository()
645
        if made_controldir._format.colocated_branches:
646
            # Formats that support colocated branches sometimes have a default
647
            # branch that is a reference branch (such as Git). Cope with
648
            # those by creating a different colocated branch.
649
            name = 'foo'
650
        else:
651
            name = None
652
        try:
653
            made_branch = made_controldir.create_branch(name)
654
        except errors.UninitializableFormat:
655
            raise tests.TestNotApplicable('Uninitializable branch format')
656
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
657
        self.assertEqual(None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
658
                         made_branch._format.get_reference(made_branch.controldir, name))
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
659
3078.2.7 by Ian Clatworthy
added smoke test for set_reference
660
    def test_set_reference(self):
661
        """set_reference on all regular branches should be callable."""
662
        if not self.branch_format.is_supported():
663
            # unsupported formats are not loopback testable
664
            # because the default open will not open them and
665
            # they may not be initializable.
666
            return
667
        this_branch = self.make_branch('this')
668
        other_branch = self.make_branch('other')
669
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
670
            this_branch._format.set_reference(this_branch.controldir, None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
671
                                              other_branch)
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
672
        except (NotImplementedError, errors.IncompatibleFormat):
3078.2.7 by Ian Clatworthy
added smoke test for set_reference
673
            # that's ok
674
            pass
675
        else:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
676
            ref = this_branch._format.get_reference(this_branch.controldir)
6874.1.2 by Jelmer Vernooij
Consistently use Branch.user_url.
677
            self.assertEqual(ref, other_branch.user_url)
3078.2.7 by Ian Clatworthy
added smoke test for set_reference
678
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
679
    def test_format_initialize_find_open(self):
680
        # loopback test to check the current format initializes to itself.
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
681
        if not self.branch_format.is_supported():
682
            # unsupported formats are not loopback testable
683
            # because the default open will not open them and
684
            # they may not be initializable.
685
            return
686
        # supported formats must be able to init and open
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
687
        t = self.get_transport()
6039.1.5 by Jelmer Vernooij
Add get_transport_from_url and get_transport_from_path functions.
688
        readonly_t = transport.get_transport_from_url(self.get_readonly_url())
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
689
        made_branch = self.make_branch('.')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
690
        self.assertIsInstance(made_branch, _mod_branch.Branch)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
691
692
        # find it via bzrdir opening:
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
693
        opened_control = controldir.ControlDir.open(readonly_t.base)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
694
        direct_opened_branch = opened_control.open_branch()
695
        self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
696
        self.assertEqual(opened_control, direct_opened_branch.controldir)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
697
        self.assertIsInstance(direct_opened_branch._format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
698
                              self.branch_format.__class__)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
699
700
        # find it via Branch.open
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
701
        opened_branch = _mod_branch.Branch.open(readonly_t.base)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
702
        self.assertIsInstance(opened_branch, made_branch.__class__)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
703
        self.assertEqual(made_branch._format.__class__,
704
                         opened_branch._format.__class__)
705
        # if it has a unique id string, can we probe for it ?
706
        try:
707
            self.branch_format.get_format_string()
708
        except NotImplementedError:
709
            return
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
710
        self.assertEqual(self.branch_format,
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
711
                         opened_control.find_branch_format())
1711.8.1 by John Arbash Meinel
Branch.lock_read/lock_write/unlock should handle failures
712
2230.3.7 by Aaron Bentley
Fix binding return values
713
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
714
class TestBound(per_branch.TestCaseWithBranch):
2230.3.6 by Aaron Bentley
work in progress bind stuff
715
716
    def test_bind_unbind(self):
717
        branch = self.make_branch('1')
718
        branch2 = self.make_branch('2')
719
        try:
720
            branch.bind(branch2)
721
        except errors.UpgradeRequired:
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
722
            raise tests.TestNotApplicable('Format does not support binding')
2230.3.7 by Aaron Bentley
Fix binding return values
723
        self.assertTrue(branch.unbind())
724
        self.assertFalse(branch.unbind())
2230.3.6 by Aaron Bentley
work in progress bind stuff
725
        self.assertIs(None, branch.get_bound_location())
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
726
727
    def test_old_bound_location(self):
728
        branch = self.make_branch('branch1')
729
        try:
730
            self.assertIs(None, branch.get_old_bound_location())
731
        except errors.UpgradeRequired:
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
732
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
733
                'Format does not store old bound locations')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
734
        branch2 = self.make_branch('branch2')
735
        branch.bind(branch2)
736
        self.assertIs(None, branch.get_old_bound_location())
737
        branch.unbind()
7143.15.2 by Jelmer Vernooij
Run autopep8.
738
        self.assertContainsRe(
739
            branch.get_old_bound_location(), '\\/branch2\\/$')
2230.3.32 by Aaron Bentley
Implement strict history policy
740
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
741
    def test_bind_diverged(self):
742
        tree_a = self.make_branch_and_tree('tree_a')
743
        tree_a.commit('rev1a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
744
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
745
        tree_a.commit('rev2a')
746
        tree_b.commit('rev2b')
747
        try:
748
            tree_b.branch.bind(tree_a.branch)
749
        except errors.UpgradeRequired:
750
            raise tests.TestNotApplicable('Format does not support binding')
751
5609.25.5 by Andrew Bennetts
Add tests that get_master_branch isn't cached when it shouldn't be, and fix a bug that reveals.
752
    def test_unbind_clears_cached_master_branch(self):
5609.25.6 by Andrew Bennetts
Docstring tweaks.
753
        """b.unbind clears any cached value of b.get_master_branch."""
5609.25.5 by Andrew Bennetts
Add tests that get_master_branch isn't cached when it shouldn't be, and fix a bug that reveals.
754
        master = self.make_branch('master')
755
        branch = self.make_branch('branch')
756
        try:
757
            branch.bind(master)
758
        except errors.UpgradeRequired:
759
            raise tests.TestNotApplicable('Format does not support binding')
760
        self.addCleanup(branch.lock_write().unlock)
761
        self.assertNotEqual(None, branch.get_master_branch())
762
        branch.unbind()
763
        self.assertEqual(None, branch.get_master_branch())
764
765
    def test_bind_clears_cached_master_branch(self):
5609.25.6 by Andrew Bennetts
Docstring tweaks.
766
        """b.bind clears any cached value of b.get_master_branch."""
5609.25.5 by Andrew Bennetts
Add tests that get_master_branch isn't cached when it shouldn't be, and fix a bug that reveals.
767
        master1 = self.make_branch('master1')
768
        master2 = self.make_branch('master2')
769
        branch = self.make_branch('branch')
770
        try:
771
            branch.bind(master1)
772
        except errors.UpgradeRequired:
773
            raise tests.TestNotApplicable('Format does not support binding')
774
        self.addCleanup(branch.lock_write().unlock)
775
        self.assertNotEqual(None, branch.get_master_branch())
776
        branch.bind(master2)
777
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
778
                                                    branch.get_master_branch().base))
5609.25.5 by Andrew Bennetts
Add tests that get_master_branch isn't cached when it shouldn't be, and fix a bug that reveals.
779
780
    def test_set_bound_location_clears_cached_master_branch(self):
5609.25.6 by Andrew Bennetts
Docstring tweaks.
781
        """b.set_bound_location clears any cached value of b.get_master_branch.
5609.25.5 by Andrew Bennetts
Add tests that get_master_branch isn't cached when it shouldn't be, and fix a bug that reveals.
782
        """
783
        master1 = self.make_branch('master1')
784
        master2 = self.make_branch('master2')
785
        branch = self.make_branch('branch')
786
        try:
787
            branch.bind(master1)
788
        except errors.UpgradeRequired:
789
            raise tests.TestNotApplicable('Format does not support binding')
790
        self.addCleanup(branch.lock_write().unlock)
791
        self.assertNotEqual(None, branch.get_master_branch())
792
        branch.set_bound_location(self.get_url('master2'))
793
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
794
                                                    branch.get_master_branch().base))
5609.25.5 by Andrew Bennetts
Add tests that get_master_branch isn't cached when it shouldn't be, and fix a bug that reveals.
795
2230.3.32 by Aaron Bentley
Implement strict history policy
796
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
797
class TestStrict(per_branch.TestCaseWithBranch):
2230.3.32 by Aaron Bentley
Implement strict history policy
798
799
    def test_strict_history(self):
800
        tree1 = self.make_branch_and_tree('tree1')
801
        try:
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
802
            tree1.branch.set_append_revisions_only(True)
2230.3.32 by Aaron Bentley
Implement strict history policy
803
        except errors.UpgradeRequired:
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
804
            raise tests.TestSkipped('Format does not support strict history')
2230.3.32 by Aaron Bentley
Implement strict history policy
805
        tree1.commit('empty commit')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
806
        tree2 = tree1.controldir.sprout('tree2').open_workingtree()
2230.3.32 by Aaron Bentley
Implement strict history policy
807
        tree2.commit('empty commit 2')
808
        tree1.pull(tree2.branch)
809
        tree1.commit('empty commit 3')
810
        tree2.commit('empty commit 4')
811
        self.assertRaises(errors.DivergedBranches, tree1.pull, tree2.branch)
812
        tree2.merge_from_branch(tree1.branch)
813
        tree2.commit('empty commit 5')
2230.3.40 by Aaron Bentley
Rename strict_revision_history to append_revisions_only
814
        self.assertRaises(errors.AppendRevisionsOnlyViolation, tree1.pull,
2230.3.32 by Aaron Bentley
Implement strict history policy
815
                          tree2.branch)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
816
        tree3 = tree1.controldir.sprout('tree3').open_workingtree()
2230.3.32 by Aaron Bentley
Implement strict history policy
817
        tree3.merge_from_branch(tree2.branch)
818
        tree3.commit('empty commit 6')
819
        tree2.pull(tree3.branch)
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
820
821
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
822
class TestIgnoreFallbacksParameter(per_branch.TestCaseWithBranch):
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
823
824
    def make_branch_with_fallback(self):
825
        fallback = self.make_branch('fallback')
826
        if not fallback._format.supports_stacking():
827
            raise tests.TestNotApplicable("format does not support stacking")
828
        stacked = self.make_branch('stacked')
829
        stacked.set_stacked_on_url(fallback.base)
830
        return stacked
831
832
    def test_fallbacks_not_opened(self):
833
        stacked = self.make_branch_with_fallback()
834
        self.get_transport('').rename('fallback', 'moved')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
835
        reopened_dir = controldir.ControlDir.open(stacked.base)
6155.6.14 by Jelmer Vernooij
Fix reopening of remote dirs.
836
        reopened = reopened_dir.open_branch(ignore_fallbacks=True)
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
837
        self.assertEqual([], reopened.repository._fallback_repositories)
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
838
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
839
    def test_fallbacks_are_opened(self):
840
        stacked = self.make_branch_with_fallback()
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
841
        reopened_dir = controldir.ControlDir.open(stacked.base)
6155.6.14 by Jelmer Vernooij
Fix reopening of remote dirs.
842
        reopened = reopened_dir.open_branch(ignore_fallbacks=False)
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
843
        self.assertLength(1, reopened.repository._fallback_repositories)
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
844
845
5158.6.2 by Martin Pool
Branch provides user_url etc
846
class TestBranchControlComponent(per_branch.TestCaseWithBranch):
847
    """Branch implementations adequately implement ControlComponent."""
6155.2.2 by Vincent Ladeuil
Add a smoke test as suggested in review.
848
5158.6.2 by Martin Pool
Branch provides user_url etc
849
    def test_urls(self):
850
        br = self.make_branch('branch')
851
        self.assertIsInstance(br.user_url, str)
852
        self.assertEqual(br.user_url, br.user_transport.base)
853
        self.assertEqual(br.control_url, br.control_transport.base)
6538.1.2 by Aaron Bentley
Migrate tests to per_branch, support RemoteBranch.
854
855
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
856
class FakeShelfCreator(object):
857
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
858
    def __init__(self, branch):
859
        self.branch = branch
860
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
861
    def write_shelf(self, shelf_file, message=None):
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
862
        tree = self.branch.repository.revision_tree(revision.NULL_REVISION)
863
        with transform.TransformPreview(tree) as tt:
864
            shelf.ShelfCreator._write_shelf(
865
                shelf_file, tt, revision.NULL_REVISION)
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
866
867
6538.1.31 by Aaron Bentley
Support foreign branches.
868
@contextlib.contextmanager
869
def skip_if_storing_uncommitted_unsupported():
870
    try:
871
        yield
872
    except errors.StoringUncommittedNotSupported:
873
        raise tests.TestNotApplicable('Cannot store uncommitted changes.')
874
875
6538.1.2 by Aaron Bentley
Migrate tests to per_branch, support RemoteBranch.
876
class TestUncommittedChanges(per_branch.TestCaseWithBranch):
877
6772.3.1 by Jelmer Vernooij
Add supports_store_uncommitted.
878
    def setUp(self):
879
        super(TestUncommittedChanges, self).setUp()
880
        if not self.branch_format.supports_store_uncommitted():
881
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
882
                'Branch format does not support store_uncommitted')
6772.3.1 by Jelmer Vernooij
Add supports_store_uncommitted.
883
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
884
    def bind(self, branch, master):
885
        try:
886
            branch.bind(master)
887
        except errors.UpgradeRequired:
888
            raise tests.TestNotApplicable('Branch cannot be bound.')
889
890
    def test_store_uncommitted(self):
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
891
        tree = self.make_branch_and_tree('b')
892
        branch = tree.branch
893
        creator = FakeShelfCreator(branch)
6538.1.31 by Aaron Bentley
Support foreign branches.
894
        with skip_if_storing_uncommitted_unsupported():
895
            self.assertIs(None, branch.get_unshelver(tree))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
896
        branch.store_uncommitted(creator)
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
897
        self.assertIsNot(None, branch.get_unshelver(tree))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
898
899
    def test_store_uncommitted_bound(self):
6538.1.31 by Aaron Bentley
Support foreign branches.
900
        tree = self.make_branch_and_tree('b')
901
        branch = tree.branch
902
        master = self.make_branch('master')
903
        self.bind(branch, master)
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
904
        creator = FakeShelfCreator(tree.branch)
905
        self.assertIs(None, tree.branch.get_unshelver(tree))
906
        self.assertIs(None, master.get_unshelver(tree))
907
        tree.branch.store_uncommitted(creator)
908
        self.assertIsNot(None, master.get_unshelver(tree))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
909
910
    def test_store_uncommitted_already_stored(self):
911
        branch = self.make_branch('b')
6538.1.31 by Aaron Bentley
Support foreign branches.
912
        with skip_if_storing_uncommitted_unsupported():
913
            branch.store_uncommitted(FakeShelfCreator(branch))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
914
        self.assertRaises(errors.ChangesAlreadyStored,
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
915
                          branch.store_uncommitted, FakeShelfCreator(branch))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
916
917
    def test_store_uncommitted_none(self):
918
        branch = self.make_branch('b')
6538.1.31 by Aaron Bentley
Support foreign branches.
919
        with skip_if_storing_uncommitted_unsupported():
920
            branch.store_uncommitted(FakeShelfCreator(branch))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
921
        branch.store_uncommitted(None)
6538.1.24 by Aaron Bentley
Eliminate get_stored_uncommitted from API.
922
        self.assertIs(None, branch.get_unshelver(None))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
923
924
    def test_get_unshelver(self):
925
        tree = self.make_branch_and_tree('tree')
926
        tree.commit('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
927
        self.build_tree_contents([('tree/file', b'contents1')])
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
928
        tree.add('file')
6538.1.31 by Aaron Bentley
Support foreign branches.
929
        with skip_if_storing_uncommitted_unsupported():
930
            tree.store_uncommitted()
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
931
        unshelver = tree.branch.get_unshelver(tree)
932
        self.assertIsNot(None, unshelver)
933
934
    def test_get_unshelver_bound(self):
935
        tree = self.make_branch_and_tree('tree')
936
        tree.commit('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
937
        self.build_tree_contents([('tree/file', b'contents1')])
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
938
        tree.add('file')
6538.1.31 by Aaron Bentley
Support foreign branches.
939
        with skip_if_storing_uncommitted_unsupported():
940
            tree.store_uncommitted()
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
941
        branch = self.make_branch('branch')
942
        self.bind(branch, tree.branch)
943
        unshelver = branch.get_unshelver(tree)
944
        self.assertIsNot(None, unshelver)
7339.1.2 by Jelmer Vernooij
Add stores_revno method to BranchFormat.
945
946
947
class TestFormatMetadata(per_branch.TestCaseWithBranch):
948
949
    def test_stores_revno(self):
950
        self.assertIn(self.branch_format.stores_revno(), (True, False))