/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 (
40
    branch as _mod_bzrbranch,
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
41
    remote,
6670.4.3 by Jelmer Vernooij
Fix more imports.
42
    )
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
43
from breezy.sixish import (
44
    text_type,
45
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
46
from breezy.tests import (
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
47
    per_branch,
48
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
49
from breezy.tests.http_server import HttpServer
50
from breezy.transport import memory
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
51
52
53
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.
54
55
    def test_branch_format_matches_bzrdir_branch_format(self):
56
        bzrdir_branch_format = self.bzrdir_format.get_branch_format()
6747.2.3 by Jelmer Vernooij
Fix formatting.
57
        self.assertIs(
7143.15.2 by Jelmer Vernooij
Run autopep8.
58
            self.branch_format.__class__,
59
            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.
60
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.
61
    def test_make_branch_gets_expected_format(self):
62
        branch = self.make_branch('.')
6747.2.3 by Jelmer Vernooij
Fix formatting.
63
        self.assertIs(
7143.15.2 by Jelmer Vernooij
Run autopep8.
64
            self.branch_format.__class__,
65
            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.
66
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.
67
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
68
class TestBranch(per_branch.TestCaseWithBranch):
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
69
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
70
    def test_create_tree_with_merge(self):
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
71
        tree, revmap = self.create_tree_with_merge()
3287.6.9 by Robert Collins
One last use of deprecated methods.
72
        tree.lock_read()
73
        self.addCleanup(tree.unlock)
74
        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.
75
        ancestry_graph = graph.get_parent_map(
76
            tree.branch.repository.all_revision_ids())
6973.6.2 by Jelmer Vernooij
Fix more tests.
77
        self.assertEqual({revmap['1']: (b'null:',),
6747.4.2 by Jelmer Vernooij
Avoid setting revision ids in a few more places.
78
                          revmap['2']: (revmap['1'], ),
79
                          revmap['1.1.1']: (revmap['1'], ),
80
                          revmap['3']: (revmap['2'], revmap['1.1.1'], ),
81
                          }, ancestry_graph)
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
82
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
83
    def test_revision_ids_are_utf8(self):
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
84
        wt = self.make_branch_and_tree('tree')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
85
        rev1 = wt.commit('f')
86
        rev2 = wt.commit('f')
87
        rev3 = wt.commit('f')
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
88
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
89
        br = self.get_branch()
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
90
        br.fetch(wt.branch)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
91
        br.generate_revision_history(rev3)
92
        for revision_id in [rev3, rev2, rev1]:
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
93
            self.assertIsInstance(revision_id, bytes)
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
94
        last = br.last_revision()
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.19 by John Arbash Meinel
Track through the new Branch6 code, and make sure revision ids are utf8
97
        revno, last = br.last_revision_info()
98
        self.assertEqual(3, revno)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
99
        self.assertEqual(rev3, last)
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
100
        self.assertIsInstance(last, bytes)
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
101
1260 by Martin Pool
- some updates for fetch/update function
102
    def test_fetch_revisions(self):
103
        """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.
104
        wt = self.make_branch_and_tree('b1')
105
        b1 = wt.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
106
        self.build_tree_contents([('b1/foo', b'hello')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
107
        wt.add(['foo'])
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
108
        rev1 = wt.commit('lala!', allow_pointless=False)
1260 by Martin Pool
- some updates for fetch/update function
109
2381.1.3 by Robert Collins
Review feedback.
110
        b2 = self.make_branch('b2')
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
111
        b2.fetch(b1)
1260 by Martin Pool
- some updates for fetch/update function
112
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
113
        rev = b2.repository.get_revision(rev1)
114
        tree = b2.repository.revision_tree(rev1)
3015.2.1 by Robert Collins
Lock correctness in branch implementation tests.
115
        tree.lock_read()
116
        self.addCleanup(tree.unlock)
6973.6.1 by Jelmer Vernooij
More bees.
117
        self.assertEqual(tree.get_file_text('foo'), b'hello')
1260 by Martin Pool
- some updates for fetch/update function
118
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
119
    def get_unbalanced_tree_pair(self):
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
120
        """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.
121
        tree_a = self.make_branch_and_tree('a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
122
        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.
123
        tree_a.add('b')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
124
        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.
125
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.
126
        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.
127
        return tree_a, tree_b
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
128
129
    def get_balanced_branch_pair(self):
130
        """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.
131
        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.
132
        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.
133
        return tree_a, tree_b
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
134
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
135
    def test_clone_partial(self):
1393.1.23 by Martin Pool
- fix cloning of part of a branch
136
        """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.
137
        # TODO: RBC 20060208 test with a revision not on revision-history.
138
        #       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).
139
        # 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.
140
        wt_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
141
        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.
142
        wt_a.add(['one'])
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
143
        rev1 = wt_a.commit('commit one')
2381.1.3 by Robert Collins
Review feedback.
144
        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.
145
        wt_a.add(['two'])
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
146
        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).
147
        # 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.
148
        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).
149
        wt_a.branch.repository.copy_content_into(repo_b)
150
        # wt_a might be a lightweight checkout, so get a hold of the actual
151
        # branch (because you can't do a partial clone of a lightweight
152
        # checkout).
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
153
        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).
154
        # Then make a branch where the new repository is, but specify a revision
155
        # ID.  The new branch's history will stop at the specified revision.
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
156
        br_b = branch.clone(repo_b.controldir, revision_id=rev1)
157
        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.
158
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
159
    def get_parented_branch(self):
160
        wt_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
161
        self.build_tree(['a/one'])
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
162
        wt_a.add(['one'])
6746.1.3 by Jelmer Vernooij
Reuse CannotSetRevisionId error.
163
        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)
164
7143.15.2 by Jelmer Vernooij
Run autopep8.
165
        branch_b = wt_a.branch.controldir.sprout(
166
            'b', revision_id=rev1).open_branch()
6874.1.2 by Jelmer Vernooij
Consistently use Branch.user_url.
167
        self.assertEqual(wt_a.branch.user_url, branch_b.get_parent())
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
168
        return branch_b
169
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.
170
    def test_clone_branch_nickname(self):
171
        # test the nick name is preserved always
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
172
        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.
173
174
    def test_clone_branch_parent(self):
175
        # 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)
176
        branch_b = self.get_parented_branch()
177
        repo_c = self.make_repository('c')
178
        branch_b.repository.copy_content_into(repo_c)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
179
        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)
180
        self.assertNotEqual(None, branch_c.get_parent())
181
        self.assertEqual(branch_b.get_parent(), branch_c.get_parent())
182
183
        # 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).
184
        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)
185
        branch_b.set_parent(random_parent)
186
        repo_d = self.make_repository('d')
187
        branch_b.repository.copy_content_into(repo_d)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
188
        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)
189
        self.assertEqual(random_parent, branch_d.get_parent())
190
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
191
    def test_submit_branch(self):
192
        """Submit location can be queried and set"""
193
        branch = self.make_branch('branch')
194
        self.assertEqual(branch.get_submit_branch(), None)
195
        branch.set_submit_branch('sftp://example.com')
196
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.com')
197
        branch.set_submit_branch('sftp://example.net')
198
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.net')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
199
1551.12.44 by Aaron Bentley
Add (set|get)_public_branch
200
    def test_public_branch(self):
201
        """public location can be queried and set"""
202
        branch = self.make_branch('branch')
203
        self.assertEqual(branch.get_public_branch(), None)
204
        branch.set_public_branch('sftp://example.com')
205
        self.assertEqual(branch.get_public_branch(), 'sftp://example.com')
206
        branch.set_public_branch('sftp://example.net')
207
        self.assertEqual(branch.get_public_branch(), 'sftp://example.net')
208
        branch.set_public_branch(None)
209
        self.assertEqual(branch.get_public_branch(), None)
210
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.
211
    def test_record_initial_ghost(self):
212
        """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.
213
        wt = self.make_branch_and_tree('.')
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
214
        if not wt.branch.repository._format.supports_ghosts:
215
            raise tests.TestNotApplicable("repository format does not "
7143.15.2 by Jelmer Vernooij
Run autopep8.
216
                                          "support ghosts")
6973.6.2 by Jelmer Vernooij
Fix more tests.
217
        wt.set_parent_ids([b'non:existent@rev--ision--0--2'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
218
                          allow_leftmost_as_ghost=True)
6973.6.2 by Jelmer Vernooij
Fix more tests.
219
        self.assertEqual([b'non:existent@rev--ision--0--2'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
220
                         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.
221
        rev_id = wt.commit('commit against a ghost first parent.')
222
        rev = wt.branch.repository.get_revision(rev_id)
6973.7.5 by Jelmer Vernooij
s/file/open.
223
        self.assertEqual(rev.parent_ids, [b'non:existent@rev--ision--0--2'])
1092.2.25 by Robert Collins
support ghosts in commits
224
        # parent_sha1s is not populated now, WTF. rbc 20051003
225
        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.
226
227
    def test_record_two_ghosts(self):
228
        """Recording with all ghosts works."""
229
        wt = self.make_branch_and_tree('.')
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
230
        if not wt.branch.repository._format.supports_ghosts:
231
            raise tests.TestNotApplicable("repository format does not "
7143.15.2 by Jelmer Vernooij
Run autopep8.
232
                                          "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.
233
        wt.set_parent_ids([
7143.15.2 by Jelmer Vernooij
Run autopep8.
234
            b'foo@azkhazan-123123-abcabc',
235
            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.
236
            ],
237
            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.
238
        rev_id = wt.commit("commit from ghost base with one merge")
239
        # the revision should have been committed with two parents
240
        rev = wt.branch.repository.get_revision(rev_id)
6973.6.2 by Jelmer Vernooij
Fix more tests.
241
        self.assertEqual([b'foo@azkhazan-123123-abcabc',
7143.15.2 by Jelmer Vernooij
Run autopep8.
242
                          b'wibble@fofof--20050401--1928390812'],
243
                         rev.parent_ids)
1092.2.25 by Robert Collins
support ghosts in commits
244
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
245
    def test_bad_revision(self):
1534.4.28 by Robert Collins
first cut at merge from integration.
246
        self.assertRaises(errors.InvalidRevisionId,
247
                          self.get_branch().repository.get_revision,
248
                          None)
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
249
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
250
    def test_nicks_bzr(self):
251
        """Test the behaviour of branch nicks specific to bzr branches.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
252
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.
253
        Nicknames are implicitly the name of the branch's directory, unless an
254
        explicit nickname is set.  That is, an explicit nickname always
255
        overrides the implicit one.
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
256
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.
257
        """
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
258
        t = self.get_transport()
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
259
        branch = self.make_branch('bzr.dev')
6653.1.2 by Jelmer Vernooij
Fix imports.
260
        if not isinstance(branch, _mod_bzrbranch.BzrBranch):
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
261
            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.
262
        # The nick will be 'bzr.dev', because there is no explicit nick set.
1185.35.11 by Aaron Bentley
Added support for branch nicks
263
        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.
264
        # Move the branch to a different directory, 'bzr.ab'.  Now that branch
265
        # 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.
266
        t.move('bzr.dev', 'bzr.ab')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
267
        branch = _mod_branch.Branch.open(self.get_url('bzr.ab'))
1185.35.11 by Aaron Bentley
Added support for branch nicks
268
        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.
269
        # Set the branch nick explicitly.  This will ensure there's a branch
270
        # config file in the branch.
271
        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)
272
        if not isinstance(branch, remote.RemoteBranch):
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
273
            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.
274
        # Because the nick has been set explicitly, the nick is now always
275
        # "Aaron's branch", regardless of directory name.
1185.35.11 by Aaron Bentley
Added support for branch nicks
276
        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.
277
        t.move('bzr.ab', 'integration')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
278
        branch = _mod_branch.Branch.open(self.get_url('integration'))
1185.35.11 by Aaron Bentley
Added support for branch nicks
279
        self.assertEqual(branch.nick, "Aaron's branch")
1185.35.12 by Aaron Bentley
Got writes of existing tree configs working.
280
        branch.nick = u"\u1234"
281
        self.assertEqual(branch.nick, u"\u1234")
1185.35.11 by Aaron Bentley
Added support for branch nicks
282
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
283
    def test_nicks(self):
284
        """Test explicit and implicit branch nicknames.
285
286
        A nickname is always available, whether set explicitly or not.
287
        """
288
        t = self.get_transport()
289
        branch = self.make_branch('bzr.dev')
290
        # An implicit nick name is set; what it is exactly depends on the
291
        # format.
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
292
        self.assertIsInstance(branch.nick, text_type)
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
293
        # Set the branch nick explicitly.
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
294
        branch.nick = u"Aaron's branch"
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
295
        # Because the nick has been set explicitly, the nick is now always
296
        # "Aaron's branch".
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
297
        self.assertEqual(branch.nick, u"Aaron's branch")
6162.2.3 by Jelmer Vernooij
Fix nick tests against foreign formats.
298
        branch.nick = u"\u1234"
299
        self.assertEqual(branch.nick, u"\u1234")
300
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
301
    def test_commit_nicks(self):
302
        """Nicknames are committed to the revision"""
303
        wt = self.make_branch_and_tree('bzr.dev')
304
        branch = wt.branch
305
        branch.nick = "My happy branch"
306
        wt.commit('My commit respect da nick.')
307
        committed = branch.repository.get_revision(branch.last_revision())
6820.1.1 by Jelmer Vernooij
add RepositoryFormat.supports_storing_branch_nick.
308
        if branch.repository._format.supports_storing_branch_nick:
309
            self.assertEqual(committed.properties["branch-nick"],
310
                             "My happy branch")
311
        else:
312
            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.
313
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
314
    def test_create_colocated(self):
315
        try:
316
            repo = self.make_repository('.', shared=True)
317
        except errors.IncompatibleFormat:
318
            return
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
319
        if repo.controldir._format.colocated_branches:
6437.21.9 by Jelmer Vernooij
Some fixes.
320
            raise tests.TestNotApplicable(
321
                "control dir does not support colocated branches")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
322
        self.assertEqual(0, len(repo.controldir.list_branches()))
6437.21.7 by Jelmer Vernooij
Fix remaining tests.
323
        if not self.bzrdir_format.colocated_branches:
324
            raise tests.TestNotApplicable("control dir format does not support "
7143.15.2 by Jelmer Vernooij
Run autopep8.
325
                                          "colocated branches")
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
326
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
327
            child_branch1 = self.branch_format.initialize(repo.controldir,
328
                                                          name='branch1')
6437.21.9 by Jelmer Vernooij
Some fixes.
329
        except errors.UninitializableFormat:
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
330
            # branch references are not default init'able and
331
            # not all bzrdirs support colocated branches.
332
            return
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
333
        self.assertEqual(1, len(repo.controldir.list_branches()))
334
        self.branch_format.initialize(repo.controldir, name='branch2')
335
        self.assertEqual(2, len(repo.controldir.list_branches()))
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
336
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
337
    def test_create_append_revisions_only(self):
338
        try:
339
            repo = self.make_repository('.', shared=True)
340
        except errors.IncompatibleFormat:
341
            return
342
        for val in (True, False):
343
            try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
344
                branch = self.branch_format.initialize(repo.controldir,
7143.15.2 by Jelmer Vernooij
Run autopep8.
345
                                                       append_revisions_only=True)
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
346
            except (errors.UninitializableFormat, errors.UpgradeRequired):
347
                # branch references are not default init'able and
348
                # not all branches support append_revisions_only
349
                return
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
350
            self.assertEqual(True, branch.get_append_revisions_only())
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
351
            repo.controldir.destroy_branch()
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
352
6123.9.14 by Jelmer Vernooij
Fix RemoteBranch.get_append_revisions_only().
353
    def test_get_set_append_revisions_only(self):
354
        branch = self.make_branch('.')
355
        if branch._format.supports_set_append_revisions_only():
356
            branch.set_append_revisions_only(True)
357
            self.assertTrue(branch.get_append_revisions_only())
358
            branch.set_append_revisions_only(False)
359
            self.assertFalse(branch.get_append_revisions_only())
360
        else:
361
            self.assertRaises(errors.UpgradeRequired,
7143.15.2 by Jelmer Vernooij
Run autopep8.
362
                              branch.set_append_revisions_only, True)
6123.9.14 by Jelmer Vernooij
Fix RemoteBranch.get_append_revisions_only().
363
            self.assertFalse(branch.get_append_revisions_only())
364
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
365
    def test_create_open_branch_uses_repository(self):
366
        try:
367
            repo = self.make_repository('.', shared=True)
368
        except errors.IncompatibleFormat:
6162.5.1 by Jelmer Vernooij
Skip test if control dir format is not initializable.
369
            raise tests.TestNotApplicable("requires shared repository support")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
370
        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.
371
        child_transport.mkdir('.')
6162.3.1 by Jelmer Vernooij
Skip a few tests for uninitializable formats.
372
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
373
            child_dir = self.bzrdir_format.initialize_on_transport(
374
                child_transport)
6162.3.1 by Jelmer Vernooij
Skip a few tests for uninitializable formats.
375
        except errors.UninitializableFormat:
7143.15.2 by Jelmer Vernooij
Run autopep8.
376
            raise tests.TestNotApplicable(
377
                "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.
378
        try:
379
            child_branch = self.branch_format.initialize(child_dir)
380
        except errors.UninitializableFormat:
381
            # branch references are not default init'able.
382
            return
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
383
        self.assertEqual(repo.controldir.root_transport.base,
384
                         child_branch.repository.controldir.root_transport.base)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
385
        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.
386
        self.assertEqual(repo.controldir.root_transport.base,
387
                         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.
388
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
389
    def test_format_description(self):
390
        tree = self.make_branch_and_tree('tree')
391
        text = tree.branch._format.get_format_description()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
392
        self.assertTrue(len(text))
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
393
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
394
    def test_get_commit_builder(self):
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
395
        branch = self.make_branch(".")
396
        branch.lock_write()
397
        builder = branch.get_commit_builder([])
398
        self.assertIsInstance(builder, repository.CommitBuilder)
399
        branch.repository.commit_write_group()
400
        branch.unlock()
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
401
1792.1.1 by Robert Collins
Factor out revision-history synthesis to make it reusable as Branch.generate_revision_history.
402
    def test_generate_revision_history(self):
403
        """Create a fake revision history easily."""
404
        tree = self.make_branch_and_tree('.')
405
        rev1 = tree.commit('foo')
6165.4.6 by Jelmer Vernooij
Avoid more uses of revision_history.
406
        tree.lock_write()
407
        self.addCleanup(tree.unlock)
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
408
        graph = tree.branch.repository.get_graph()
6165.4.16 by Jelmer Vernooij
Don't provide Branch.iter_reverse_revision_history.
409
        orig_history = list(
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
410
            graph.iter_lefthand_ancestry(
411
                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.
412
        rev2 = tree.commit('bar', allow_pointless=True)
413
        tree.branch.generate_revision_history(rev1)
6165.4.16 by Jelmer Vernooij
Don't provide Branch.iter_reverse_revision_history.
414
        self.assertEqual(orig_history, list(
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
415
            graph.iter_lefthand_ancestry(
416
                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.
417
1836.3.1 by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION.
418
    def test_generate_revision_history_NULL_REVISION(self):
419
        tree = self.make_branch_and_tree('.')
420
        rev1 = tree.commit('foo')
6165.4.6 by Jelmer Vernooij
Avoid more uses of revision_history.
421
        tree.lock_write()
422
        self.addCleanup(tree.unlock)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
423
        tree.branch.generate_revision_history(revision.NULL_REVISION)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
424
        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.
425
1551.8.6 by Aaron Bentley
Rename test
426
    def test_create_checkout(self):
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
427
        tree_a = self.make_branch_and_tree('a')
428
        branch_a = tree_a.branch
1551.8.5 by Aaron Bentley
Change name to create_checkout
429
        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.
430
        self.assertEqual(b'null:', checkout_b.last_revision())
6876.1.1 by Jelmer Vernooij
Allow InterBranch to not implement lossless fetch.
431
        try:
432
            rev1 = checkout_b.commit('rev1')
433
        except errors.NoRoundtrippingSupport:
434
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
435
                'roundtripping between %r and %r not supported' %
436
                (checkout_b.branch, checkout_b.branch.get_master_branch()))
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
437
        self.assertEqual(rev1, branch_a.last_revision())
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
438
        self.assertNotEqual(checkout_b.branch.base, branch_a.base)
439
1551.8.5 by Aaron Bentley
Change name to create_checkout
440
        checkout_c = branch_a.create_checkout('c', lightweight=True)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
441
        self.assertEqual(rev1, checkout_c.last_revision())
442
        rev2 = checkout_c.commit('rev2')
443
        self.assertEqual(rev2, branch_a.last_revision())
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
444
        self.assertEqual(checkout_c.branch.base, branch_a.base)
445
1551.8.5 by Aaron Bentley
Change name to create_checkout
446
        checkout_d = branch_a.create_checkout('d', lightweight=True)
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
447
        self.assertEqual(rev2, checkout_d.last_revision())
1551.8.5 by Aaron Bentley
Change name to create_checkout
448
        checkout_e = branch_a.create_checkout('e')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
449
        self.assertEqual(rev2, checkout_e.last_revision())
1425 by Robert Collins
merge from Aaron - unbreaks open_containing and the fetch progress bar
450
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
451
    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
452
        """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
453
        tree_a = self.make_branch_and_tree('a')
454
        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.
455
        # open the branch via a readonly transport
6217.3.1 by Jelmer Vernooij
Skip tests against formats that don't support readonly modifier.
456
        url = self.get_readonly_url(urlutils.basename(tree_a.branch.base))
457
        t = transport.get_transport_from_url(url)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
458
        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.
459
            raise tests.TestNotApplicable("format does not support transport")
460
        source_branch = _mod_branch.Branch.open(url)
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
461
        # sanity check that the test will be valid
462
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
7143.15.2 by Jelmer Vernooij
Run autopep8.
463
                          source_branch.lock_write)
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
464
        checkout = source_branch.create_checkout('c', lightweight=True)
465
        self.assertEqual(rev_id, checkout.last_revision())
466
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
467
    def test_create_anonymous_heavyweight_checkout(self):
468
        """A regular checkout from a readonly branch should succeed."""
469
        tree_a = self.make_branch_and_tree('a')
470
        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.
471
        # open the branch via a readonly transport
6182.1.16 by Jelmer Vernooij
Merge lp:bzr
472
        url = self.get_readonly_url(
473
            osutils.basename(tree_a.branch.base.rstrip('/')))
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
474
        t = transport.get_transport_from_url(url)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
475
        if not tree_a.branch.controldir._format.supports_transport(t):
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
476
            raise tests.TestNotApplicable("format does not support transport")
477
        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
478
        # sanity check that the test will be valid
479
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
7143.15.2 by Jelmer Vernooij
Run autopep8.
480
                          source_branch.lock_write)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
481
        checkout = source_branch.create_checkout('c')
482
        self.assertEqual(rev_id, checkout.last_revision())
483
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.
484
    def test_heads_to_fetch(self):
485
        # heads_to_fetch is a method that returns a collection of revids that
486
        # need to be fetched to copy this branch into another repo.  At a
487
        # minimum this will include the tip.
488
        # (In native formats, this is the tip + tags, but other formats may
489
        # have other revs needed)
490
        tree = self.make_branch_and_tree('a')
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
491
        tree.commit('first commit')
492
        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.
493
        must_fetch, should_fetch = tree.branch.heads_to_fetch()
6747.2.1 by Jelmer Vernooij
Avoid setting revision_ids.
494
        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.
495
496
    def test_heads_to_fetch_not_null_revision(self):
497
        # NULL_REVISION does not appear in the result of heads_to_fetch, even
498
        # for an empty branch.
499
        tree = self.make_branch_and_tree('a')
500
        must_fetch, should_fetch = tree.branch.heads_to_fetch()
501
        self.assertFalse(revision.NULL_REVISION in must_fetch)
502
        self.assertFalse(revision.NULL_REVISION in should_fetch)
503
6883.8.1 by Jelmer Vernooij
Add Branch.create_memorytree.
504
    def test_create_memorytree(self):
505
        tree = self.make_branch_and_tree('a')
506
        self.assertIsInstance(tree.branch.create_memorytree(), _mod_tree.Tree)
507
1551.8.4 by Aaron Bentley
Tweak import style
508
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
509
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.
510
511
    def test_branch_format_network_name(self):
512
        br = self.make_branch('.')
513
        format = br._format
514
        network_name = format.network_name()
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
515
        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.
516
        # We want to test that the network_name matches the actual format on
517
        # disk. For local branches that means that using network_name as a key
518
        # in the registry gives back the same format. For remote branches we
519
        # check that the network_name of the RemoteBranchFormat we have locally
520
        # matches the actual format present on disk.
521
        if isinstance(format, remote.RemoteBranchFormat):
522
            br._ensure_real()
523
            real_branch = br._real_branch
524
            self.assertEqual(real_branch._format.network_name(), network_name)
525
        else:
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
526
            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.
527
            looked_up_format = registry.get(network_name)
528
            self.assertEqual(format.__class__, looked_up_format.__class__)
529
6449.4.2 by Jelmer Vernooij
Fix test name.
530
    def test_get_config_calls(self):
6155.2.2 by Vincent Ladeuil
Add a smoke test as suggested in review.
531
        # Smoke test that all branch succeed getting a config
532
        br = self.make_branch('.')
533
        br.get_config()
534
        br.get_config_stack()
535
4032.3.1 by Robert Collins
Add a BranchFormat.network_name() method as preparation for creating branches via RPC calls.
536
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
537
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.
538
    """A support class that provides readonly urls outside the local namespace.
539
540
    This is done by checking if self.transport_server is a MemoryServer. if it
541
    is then we are chrooted already, if it is not then an HttpServer is used
542
    for readonly urls.
543
    """
544
545
    def setUp(self):
546
        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.
547
        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.
548
            self.transport_readonly_server = HttpServer
1425 by Robert Collins
merge from Aaron - unbreaks open_containing and the fetch progress bar
549
1185.12.18 by Aaron Bentley
Fixed error handling when NotBranch on HTTP
550
    def test_open_containing(self):
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
551
        self.assertRaises(errors.NotBranchError,
552
                          _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.
553
                          self.get_readonly_url(''))
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
554
        self.assertRaises(errors.NotBranchError,
555
                          _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.
556
                          self.get_readonly_url('g/p/q'))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
557
        branch = self.make_branch('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
558
        if not branch.controldir._format.supports_transport(
7143.15.2 by Jelmer Vernooij
Run autopep8.
559
                transport.get_transport_from_url(self.get_readonly_url('.'))):
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
560
            raise tests.TestNotApplicable("format does not support transport")
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
561
        branch, relpath = _mod_branch.Branch.open_containing(
562
            self.get_readonly_url(''))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
563
        self.assertEqual('', relpath)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
564
        branch, relpath = _mod_branch.Branch.open_containing(
565
            self.get_readonly_url('g/p/q'))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
566
        self.assertEqual('g/p/q', relpath)
2929.3.21 by Vincent Ladeuil
Merge bzr.dev, resolve conflicts.
567
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
568
569
class InstrumentedTransaction(object):
570
571
    def finish(self):
572
        self.calls.append('finish')
573
574
    def __init__(self):
575
        self.calls = []
576
577
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
578
class TestDecorator(object):
579
580
    def __init__(self):
581
        self._calls = []
582
583
    def lock_read(self):
584
        self._calls.append('lr')
6754.8.9 by Jelmer Vernooij
Fix more tests.
585
        return lock.LogicalLockResult(self.unlock)
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
586
587
    def lock_write(self):
588
        self._calls.append('lw')
6754.8.9 by Jelmer Vernooij
Fix more tests.
589
        return lock.LogicalLockResult(self.unlock)
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
590
591
    def unlock(self):
592
        self._calls.append('ul')
593
594
    def do_with_read(self):
6754.8.9 by Jelmer Vernooij
Fix more tests.
595
        with self.lock_read():
596
            return 1
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
597
598
    def except_with_read(self):
6754.8.9 by Jelmer Vernooij
Fix more tests.
599
        with self.lock_read():
600
            raise RuntimeError
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
601
602
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
603
class TestBranchPushLocations(per_branch.TestCaseWithBranch):
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
604
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
605
    def test_get_push_location_unset(self):
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
606
        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.
607
608
    def test_get_push_location_exact(self):
5345.1.19 by Vincent Ladeuil
Cleanup bt.per_branch.test_branch.
609
        b = self.get_branch()
5345.1.26 by Vincent Ladeuil
Merge lockable-config-files into remove-gratuitous-ensure-config-dir-exist-calls resolving conflicts
610
        config.LocationConfig.from_string(
5345.1.25 by Vincent Ladeuil
Move the '_save' parameter from '__init__' to 'from_bytes', fix fallouts.
611
            '[%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.
612
        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.
613
614
    def test_set_push_location(self):
1878.1.3 by John Arbash Meinel
some test cleanups
615
        branch = self.get_branch()
616
        branch.set_push_location('foo')
2230.3.3 by Aaron Bentley
Add more config testing
617
        self.assertEqual('foo', branch.get_push_location())
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
618
619
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
620
class TestChildSubmitFormats(per_branch.TestCaseWithBranch):
4382.3.1 by Jelmer Vernooij
Add Branch.get_child_submit_format(), so particular Branch implementations
621
622
    def test_get_child_submit_format_default(self):
6104.2.4 by Jelmer Vernooij
Allow get_child_submit_format to return a string.
623
        submit_format = self.get_branch().get_child_submit_format()
624
        self.assertTrue(submit_format is None or
7018.3.2 by Jelmer Vernooij
Fix some git tests.
625
                        isinstance(submit_format, str))
4382.3.1 by Jelmer Vernooij
Add Branch.get_child_submit_format(), so particular Branch implementations
626
627
    def test_get_child_submit_format(self):
628
        branch = self.get_branch()
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
629
        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
630
        branch = self.get_branch()
631
        self.assertEqual('10', branch.get_child_submit_format())
632
633
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
634
class TestFormat(per_branch.TestCaseWithBranch):
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
635
    """Tests for the format itself."""
636
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
637
    def test_get_reference(self):
638
        """get_reference on all regular branches should return None."""
639
        if not self.branch_format.is_supported():
640
            # unsupported formats are not loopback testable
641
            # because the default open will not open them and
642
            # they may not be initializable.
643
            return
6883.19.1 by Jelmer Vernooij
Allow default branch to be a branch reference.
644
        made_controldir = self.make_controldir('.')
645
        made_controldir.create_repository()
646
        if made_controldir._format.colocated_branches:
647
            # Formats that support colocated branches sometimes have a default
648
            # branch that is a reference branch (such as Git). Cope with
649
            # those by creating a different colocated branch.
650
            name = 'foo'
651
        else:
652
            name = None
653
        try:
654
            made_branch = made_controldir.create_branch(name)
655
        except errors.UninitializableFormat:
656
            raise tests.TestNotApplicable('Uninitializable branch format')
657
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
658
        self.assertEqual(None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
659
                         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.
660
3078.2.7 by Ian Clatworthy
added smoke test for set_reference
661
    def test_set_reference(self):
662
        """set_reference on all regular branches should be callable."""
663
        if not self.branch_format.is_supported():
664
            # unsupported formats are not loopback testable
665
            # because the default open will not open them and
666
            # they may not be initializable.
667
            return
668
        this_branch = self.make_branch('this')
669
        other_branch = self.make_branch('other')
670
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
671
            this_branch._format.set_reference(this_branch.controldir, None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
672
                                              other_branch)
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
673
        except (NotImplementedError, errors.IncompatibleFormat):
3078.2.7 by Ian Clatworthy
added smoke test for set_reference
674
            # that's ok
675
            pass
676
        else:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
677
            ref = this_branch._format.get_reference(this_branch.controldir)
6874.1.2 by Jelmer Vernooij
Consistently use Branch.user_url.
678
            self.assertEqual(ref, other_branch.user_url)
3078.2.7 by Ian Clatworthy
added smoke test for set_reference
679
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
680
    def test_format_initialize_find_open(self):
681
        # 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.
682
        if not self.branch_format.is_supported():
683
            # unsupported formats are not loopback testable
684
            # because the default open will not open them and
685
            # they may not be initializable.
686
            return
687
        # 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.
688
        t = self.get_transport()
6039.1.5 by Jelmer Vernooij
Add get_transport_from_url and get_transport_from_path functions.
689
        readonly_t = transport.get_transport_from_url(self.get_readonly_url())
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
690
        made_branch = self.make_branch('.')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
691
        self.assertIsInstance(made_branch, _mod_branch.Branch)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
692
693
        # find it via bzrdir opening:
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
694
        opened_control = controldir.ControlDir.open(readonly_t.base)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
695
        direct_opened_branch = opened_control.open_branch()
696
        self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
697
        self.assertEqual(opened_control, direct_opened_branch.controldir)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
698
        self.assertIsInstance(direct_opened_branch._format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
699
                              self.branch_format.__class__)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
700
701
        # find it via Branch.open
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
702
        opened_branch = _mod_branch.Branch.open(readonly_t.base)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
703
        self.assertIsInstance(opened_branch, made_branch.__class__)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
704
        self.assertEqual(made_branch._format.__class__,
705
                         opened_branch._format.__class__)
706
        # if it has a unique id string, can we probe for it ?
707
        try:
708
            self.branch_format.get_format_string()
709
        except NotImplementedError:
710
            return
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
711
        self.assertEqual(self.branch_format,
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
712
                         opened_control.find_branch_format())
1711.8.1 by John Arbash Meinel
Branch.lock_read/lock_write/unlock should handle failures
713
2230.3.7 by Aaron Bentley
Fix binding return values
714
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
715
class TestBound(per_branch.TestCaseWithBranch):
2230.3.6 by Aaron Bentley
work in progress bind stuff
716
717
    def test_bind_unbind(self):
718
        branch = self.make_branch('1')
719
        branch2 = self.make_branch('2')
720
        try:
721
            branch.bind(branch2)
722
        except errors.UpgradeRequired:
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
723
            raise tests.TestNotApplicable('Format does not support binding')
2230.3.7 by Aaron Bentley
Fix binding return values
724
        self.assertTrue(branch.unbind())
725
        self.assertFalse(branch.unbind())
2230.3.6 by Aaron Bentley
work in progress bind stuff
726
        self.assertIs(None, branch.get_bound_location())
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
727
728
    def test_old_bound_location(self):
729
        branch = self.make_branch('branch1')
730
        try:
731
            self.assertIs(None, branch.get_old_bound_location())
732
        except errors.UpgradeRequired:
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
733
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
734
                'Format does not store old bound locations')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
735
        branch2 = self.make_branch('branch2')
736
        branch.bind(branch2)
737
        self.assertIs(None, branch.get_old_bound_location())
738
        branch.unbind()
7143.15.2 by Jelmer Vernooij
Run autopep8.
739
        self.assertContainsRe(
740
            branch.get_old_bound_location(), '\\/branch2\\/$')
2230.3.32 by Aaron Bentley
Implement strict history policy
741
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
742
    def test_bind_diverged(self):
743
        tree_a = self.make_branch_and_tree('tree_a')
744
        tree_a.commit('rev1a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
745
        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
746
        tree_a.commit('rev2a')
747
        tree_b.commit('rev2b')
748
        try:
749
            tree_b.branch.bind(tree_a.branch)
750
        except errors.UpgradeRequired:
751
            raise tests.TestNotApplicable('Format does not support binding')
752
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.
753
    def test_unbind_clears_cached_master_branch(self):
5609.25.6 by Andrew Bennetts
Docstring tweaks.
754
        """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.
755
        master = self.make_branch('master')
756
        branch = self.make_branch('branch')
757
        try:
758
            branch.bind(master)
759
        except errors.UpgradeRequired:
760
            raise tests.TestNotApplicable('Format does not support binding')
761
        self.addCleanup(branch.lock_write().unlock)
762
        self.assertNotEqual(None, branch.get_master_branch())
763
        branch.unbind()
764
        self.assertEqual(None, branch.get_master_branch())
765
766
    def test_bind_clears_cached_master_branch(self):
5609.25.6 by Andrew Bennetts
Docstring tweaks.
767
        """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.
768
        master1 = self.make_branch('master1')
769
        master2 = self.make_branch('master2')
770
        branch = self.make_branch('branch')
771
        try:
772
            branch.bind(master1)
773
        except errors.UpgradeRequired:
774
            raise tests.TestNotApplicable('Format does not support binding')
775
        self.addCleanup(branch.lock_write().unlock)
776
        self.assertNotEqual(None, branch.get_master_branch())
777
        branch.bind(master2)
778
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
779
                                                    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.
780
781
    def test_set_bound_location_clears_cached_master_branch(self):
5609.25.6 by Andrew Bennetts
Docstring tweaks.
782
        """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.
783
        """
784
        master1 = self.make_branch('master1')
785
        master2 = self.make_branch('master2')
786
        branch = self.make_branch('branch')
787
        try:
788
            branch.bind(master1)
789
        except errors.UpgradeRequired:
790
            raise tests.TestNotApplicable('Format does not support binding')
791
        self.addCleanup(branch.lock_write().unlock)
792
        self.assertNotEqual(None, branch.get_master_branch())
793
        branch.set_bound_location(self.get_url('master2'))
794
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
795
                                                    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.
796
2230.3.32 by Aaron Bentley
Implement strict history policy
797
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
798
class TestStrict(per_branch.TestCaseWithBranch):
2230.3.32 by Aaron Bentley
Implement strict history policy
799
800
    def test_strict_history(self):
801
        tree1 = self.make_branch_and_tree('tree1')
802
        try:
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
803
            tree1.branch.set_append_revisions_only(True)
2230.3.32 by Aaron Bentley
Implement strict history policy
804
        except errors.UpgradeRequired:
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
805
            raise tests.TestSkipped('Format does not support strict history')
2230.3.32 by Aaron Bentley
Implement strict history policy
806
        tree1.commit('empty commit')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
807
        tree2 = tree1.controldir.sprout('tree2').open_workingtree()
2230.3.32 by Aaron Bentley
Implement strict history policy
808
        tree2.commit('empty commit 2')
809
        tree1.pull(tree2.branch)
810
        tree1.commit('empty commit 3')
811
        tree2.commit('empty commit 4')
812
        self.assertRaises(errors.DivergedBranches, tree1.pull, tree2.branch)
813
        tree2.merge_from_branch(tree1.branch)
814
        tree2.commit('empty commit 5')
2230.3.40 by Aaron Bentley
Rename strict_revision_history to append_revisions_only
815
        self.assertRaises(errors.AppendRevisionsOnlyViolation, tree1.pull,
2230.3.32 by Aaron Bentley
Implement strict history policy
816
                          tree2.branch)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
817
        tree3 = tree1.controldir.sprout('tree3').open_workingtree()
2230.3.32 by Aaron Bentley
Implement strict history policy
818
        tree3.merge_from_branch(tree2.branch)
819
        tree3.commit('empty commit 6')
820
        tree2.pull(tree3.branch)
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
821
822
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
823
class TestIgnoreFallbacksParameter(per_branch.TestCaseWithBranch):
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
824
825
    def make_branch_with_fallback(self):
826
        fallback = self.make_branch('fallback')
827
        if not fallback._format.supports_stacking():
828
            raise tests.TestNotApplicable("format does not support stacking")
829
        stacked = self.make_branch('stacked')
830
        stacked.set_stacked_on_url(fallback.base)
831
        return stacked
832
833
    def test_fallbacks_not_opened(self):
834
        stacked = self.make_branch_with_fallback()
835
        self.get_transport('').rename('fallback', 'moved')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
836
        reopened_dir = controldir.ControlDir.open(stacked.base)
6155.6.14 by Jelmer Vernooij
Fix reopening of remote dirs.
837
        reopened = reopened_dir.open_branch(ignore_fallbacks=True)
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
838
        self.assertEqual([], reopened.repository._fallback_repositories)
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
839
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
840
    def test_fallbacks_are_opened(self):
841
        stacked = self.make_branch_with_fallback()
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
842
        reopened_dir = controldir.ControlDir.open(stacked.base)
6155.6.14 by Jelmer Vernooij
Fix reopening of remote dirs.
843
        reopened = reopened_dir.open_branch(ignore_fallbacks=False)
4160.2.13 by Andrew Bennetts
Add some tests for ignore_fallbacks.
844
        self.assertLength(1, reopened.repository._fallback_repositories)
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
845
846
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
847
class TestReferenceLocation(per_branch.TestCaseWithBranch):
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
848
849
    def test_reference_parent(self):
850
        tree = self.make_branch_and_tree('tree')
851
        subtree = self.make_branch_and_tree('tree/subtree')
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
852
        subtree.commit('a change')
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
853
        try:
854
            tree.add_reference(subtree)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
855
        except errors.UnsupportedOperation:
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
856
            raise tests.TestNotApplicable('Tree cannot hold references.')
6182.1.6 by Jelmer Vernooij
use basename to find branch location.
857
        reference_parent = tree.branch.reference_parent(
6182.1.17 by Jelmer Vernooij
Fix two reference_parent tests.
858
            urlutils.relative_url(tree.branch.user_url, subtree.branch.user_url))
6926.2.9 by Jelmer Vernooij
Use user_url rather than base.
859
        self.assertEqual(subtree.branch.user_url, reference_parent.user_url)
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
860
4273.1.4 by Aaron Bentley
Relative reference locations are branch-relative.
861
    def test_reference_parent_accepts_possible_transports(self):
862
        tree = self.make_branch_and_tree('tree')
863
        subtree = self.make_branch_and_tree('tree/subtree')
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
864
        subtree.commit('a change')
4273.1.4 by Aaron Bentley
Relative reference locations are branch-relative.
865
        try:
866
            tree.add_reference(subtree)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
867
        except errors.UnsupportedOperation:
4273.1.4 by Aaron Bentley
Relative reference locations are branch-relative.
868
            raise tests.TestNotApplicable('Tree cannot hold references.')
6793.4.1 by Jelmer Vernooij
Improve set_root_id handling.
869
        reference_parent = tree.branch.reference_parent(
6182.1.17 by Jelmer Vernooij
Fix two reference_parent tests.
870
            urlutils.relative_url(
871
                tree.branch.user_url, subtree.branch.user_url),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
872
            possible_transports=[subtree.controldir.root_transport])
4273.1.4 by Aaron Bentley
Relative reference locations are branch-relative.
873
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
874
    def test_get_reference_info(self):
875
        branch = self.make_branch('branch')
876
        try:
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
877
            path, loc = branch.get_reference_info('file')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
878
        except errors.UnsupportedOperation:
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
879
            raise tests.TestNotApplicable('Branch cannot hold references.')
880
        self.assertIs(None, path)
881
        self.assertIs(None, loc)
882
883
    def test_set_reference_info(self):
884
        branch = self.make_branch('branch')
885
        try:
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
886
            branch.set_reference_info('path/to/file', 'path/to/location',
6973.13.2 by Jelmer Vernooij
Fix some more tests.
887
                                      b'file-id')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
888
        except errors.UnsupportedOperation:
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
889
            raise tests.TestNotApplicable('Branch cannot hold references.')
890
891
    def test_set_get_reference_info(self):
892
        branch = self.make_branch('branch')
893
        try:
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
894
            branch.set_reference_info('path/to/file',
6973.13.2 by Jelmer Vernooij
Fix some more tests.
895
                                      'path/to/location', b'file-id')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
896
        except errors.UnsupportedOperation:
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
897
            raise tests.TestNotApplicable('Branch cannot hold references.')
898
        # Create a new instance to ensure storage is permanent
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
899
        branch = _mod_branch.Branch.open('branch')
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
900
        branch_location, file_id = branch.get_reference_info('path/to/file')
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
901
        self.assertEqual('path/to/location', branch_location)
902
903
    def test_set_null_reference_info(self):
904
        branch = self.make_branch('branch')
905
        try:
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
906
            branch.set_reference_info('path/to/file',
6973.13.2 by Jelmer Vernooij
Fix some more tests.
907
                                      'path/to/location', b'file-id')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
908
        except errors.UnsupportedOperation:
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
909
            raise tests.TestNotApplicable('Branch cannot hold references.')
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
910
        branch.set_reference_info('path/to/file', None, None)
911
        branch_location, file_id = branch.get_reference_info('path/to/file')
912
        self.assertIs(None, file_id)
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
913
        self.assertIs(None, branch_location)
914
915
    def test_set_null_reference_info_when_null(self):
916
        branch = self.make_branch('branch')
917
        try:
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
918
            branch_location, file_id = branch.get_reference_info('file')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
919
        except errors.UnsupportedOperation:
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
920
            raise tests.TestNotApplicable('Branch cannot hold references.')
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
921
        self.assertIs(None, file_id)
4273.1.1 by Aaron Bentley
Implement branch format for tree references.
922
        self.assertIs(None, branch_location)
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
923
        branch.set_reference_info('path/to/file', None, None)
4273.1.2 by Aaron Bentley
Use reference_info to get reference_parent.
924
4273.1.7 by Aaron Bentley
Make update_references do a merge.
925
    def make_branch_with_reference(self, location, reference_location,
926
                                   file_id='file-id'):
927
        branch = self.make_branch(location)
4273.1.2 by Aaron Bentley
Use reference_info to get reference_parent.
928
        try:
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
929
            branch.set_reference_info('path/to/file',
930
                                      reference_location, file_id)
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
931
        except errors.UnsupportedOperation:
4273.1.2 by Aaron Bentley
Use reference_info to get reference_parent.
932
            raise tests.TestNotApplicable('Branch cannot hold references.')
4273.1.5 by Aaron Bentley
Ensure references are propagated by sprout/clone.
933
        return branch
934
935
    def test_reference_parent_from_reference_info_(self):
936
        referenced_branch = self.make_branch('reference_branch')
937
        branch = self.make_branch_with_reference('branch',
938
                                                 referenced_branch.base)
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
939
        parent = branch.reference_parent('path/to/file')
4273.1.3 by Aaron Bentley
Use branch-relative paths to references.
940
        self.assertEqual(parent.base, referenced_branch.base)
941
942
    def test_branch_relative_reference_location(self):
943
        branch = self.make_branch('branch')
944
        try:
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
945
            branch.set_reference_info('path/to/file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
946
                                      '../reference_branch', b'file-id')
5010.2.4 by Vincent Ladeuil
Fix per_branch/test_branch.py imports.
947
        except errors.UnsupportedOperation:
4273.1.3 by Aaron Bentley
Use branch-relative paths to references.
948
            raise tests.TestNotApplicable('Branch cannot hold references.')
949
        referenced_branch = self.make_branch('reference_branch')
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
950
        parent = branch.reference_parent('path/to/file')
4273.1.3 by Aaron Bentley
Use branch-relative paths to references.
951
        self.assertEqual(parent.base, referenced_branch.base)
4273.1.5 by Aaron Bentley
Ensure references are propagated by sprout/clone.
952
953
    def test_sprout_copies_reference_location(self):
4273.1.6 by Aaron Bentley
Ensure references are rebased.
954
        branch = self.make_branch_with_reference('branch', '../reference')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
955
        new_branch = branch.controldir.sprout('new-branch').open_branch()
4273.1.6 by Aaron Bentley
Ensure references are rebased.
956
        self.assertEqual('../reference',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
957
                         new_branch.get_reference_info('path/to/file')[0])
4273.1.5 by Aaron Bentley
Ensure references are propagated by sprout/clone.
958
959
    def test_clone_copies_reference_location(self):
4273.1.6 by Aaron Bentley
Ensure references are rebased.
960
        branch = self.make_branch_with_reference('branch', '../reference')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
961
        new_branch = branch.controldir.clone('new-branch').open_branch()
4273.1.6 by Aaron Bentley
Ensure references are rebased.
962
        self.assertEqual('../reference',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
963
                         new_branch.get_reference_info('path/to/file')[0])
4273.1.6 by Aaron Bentley
Ensure references are rebased.
964
965
    def test_copied_locations_are_rebased(self):
966
        branch = self.make_branch_with_reference('branch', 'reference')
7143.15.2 by Jelmer Vernooij
Run autopep8.
967
        new_branch = branch.controldir.sprout(
968
            'branch/new-branch').open_branch()
4273.1.6 by Aaron Bentley
Ensure references are rebased.
969
        self.assertEqual('../reference',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
970
                         new_branch.get_reference_info('path/to/file')[0])
4273.1.7 by Aaron Bentley
Make update_references do a merge.
971
972
    def test_update_references_retains_old_references(self):
973
        branch = self.make_branch_with_reference('branch', 'reference')
974
        new_branch = self.make_branch_with_reference(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
975
            'new_branch', 'reference', b'file-id2')
4273.1.7 by Aaron Bentley
Make update_references do a merge.
976
        new_branch.update_references(branch)
977
        self.assertEqual('reference',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
978
                         branch.get_reference_info('path/to/file')[0])
4273.1.7 by Aaron Bentley
Make update_references do a merge.
979
980
    def test_update_references_retains_known_references(self):
981
        branch = self.make_branch_with_reference('branch', 'reference')
982
        new_branch = self.make_branch_with_reference(
983
            'new_branch', 'reference2')
984
        new_branch.update_references(branch)
985
        self.assertEqual('reference',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
986
                         branch.get_reference_info('path/to/file')[0])
4273.1.7 by Aaron Bentley
Make update_references do a merge.
987
4273.1.14 by Aaron Bentley
Restore disabled test
988
    def test_update_references_skips_known_references(self):
4273.1.7 by Aaron Bentley
Make update_references do a merge.
989
        branch = self.make_branch_with_reference('branch', 'reference')
7143.15.2 by Jelmer Vernooij
Run autopep8.
990
        new_branch = branch.controldir.sprout(
991
            'branch/new-branch').open_branch()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
992
        new_branch.set_reference_info('../foo', '../foo', b'file-id')
4273.1.7 by Aaron Bentley
Make update_references do a merge.
993
        new_branch.update_references(branch)
4273.1.14 by Aaron Bentley
Restore disabled test
994
        self.assertEqual('reference',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
995
                         branch.get_reference_info('path/to/file')[0])
4273.1.8 by Aaron Bentley
Handle references in push, pull, merge.
996
997
    def test_pull_updates_references(self):
998
        branch = self.make_branch_with_reference('branch', 'reference')
7143.15.2 by Jelmer Vernooij
Run autopep8.
999
        new_branch = branch.controldir.sprout(
1000
            'branch/new-branch').open_branch()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1001
        new_branch.set_reference_info('../foo', '../foo', b'file-id2')
4273.1.8 by Aaron Bentley
Handle references in push, pull, merge.
1002
        branch.pull(new_branch)
1003
        self.assertEqual('foo',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
1004
                         branch.get_reference_info('../foo')[0])
4273.1.8 by Aaron Bentley
Handle references in push, pull, merge.
1005
1006
    def test_push_updates_references(self):
1007
        branch = self.make_branch_with_reference('branch', 'reference')
7143.15.2 by Jelmer Vernooij
Run autopep8.
1008
        new_branch = branch.controldir.sprout(
1009
            'branch/new-branch').open_branch()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1010
        new_branch.set_reference_info('../foo', '../foo', b'file-id2')
4273.1.8 by Aaron Bentley
Handle references in push, pull, merge.
1011
        new_branch.push(branch)
1012
        self.assertEqual('foo',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
1013
                         branch.get_reference_info('../foo')[0])
4273.1.8 by Aaron Bentley
Handle references in push, pull, merge.
1014
1015
    def test_merge_updates_references(self):
1016
        branch = self.make_branch_with_reference('branch', 'reference')
1017
        tree = self.make_branch_and_tree('tree')
1018
        tree.commit('foo')
1019
        branch.pull(tree.branch)
1020
        checkout = branch.create_checkout('checkout', lightweight=True)
1021
        checkout.commit('bar')
1022
        tree.lock_write()
1023
        self.addCleanup(tree.unlock)
6719.1.3 by Jelmer Vernooij
Fix remaining issues.
1024
        merger = merge.Merger.from_revision_ids(tree,
4273.1.8 by Aaron Bentley
Handle references in push, pull, merge.
1025
                                                branch.last_revision(),
1026
                                                other_branch=branch)
1027
        merger.merge_type = merge.Merge3Merger
1028
        merger.do_merge()
1029
        self.assertEqual('../branch/reference',
6926.2.5 by Jelmer Vernooij
Swap order for nested tree functions.
1030
                         tree.branch.get_reference_info('path/to/file')[0])
5158.6.2 by Martin Pool
Branch provides user_url etc
1031
1032
1033
class TestBranchControlComponent(per_branch.TestCaseWithBranch):
1034
    """Branch implementations adequately implement ControlComponent."""
6155.2.2 by Vincent Ladeuil
Add a smoke test as suggested in review.
1035
5158.6.2 by Martin Pool
Branch provides user_url etc
1036
    def test_urls(self):
1037
        br = self.make_branch('branch')
1038
        self.assertIsInstance(br.user_url, str)
1039
        self.assertEqual(br.user_url, br.user_transport.base)
1040
        self.assertEqual(br.control_url, br.control_transport.base)
6538.1.2 by Aaron Bentley
Migrate tests to per_branch, support RemoteBranch.
1041
1042
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1043
class FakeShelfCreator(object):
1044
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
1045
    def __init__(self, branch):
1046
        self.branch = branch
1047
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1048
    def write_shelf(self, shelf_file, message=None):
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
1049
        tree = self.branch.repository.revision_tree(revision.NULL_REVISION)
1050
        with transform.TransformPreview(tree) as tt:
1051
            shelf.ShelfCreator._write_shelf(
1052
                shelf_file, tt, revision.NULL_REVISION)
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1053
1054
6538.1.31 by Aaron Bentley
Support foreign branches.
1055
@contextlib.contextmanager
1056
def skip_if_storing_uncommitted_unsupported():
1057
    try:
1058
        yield
1059
    except errors.StoringUncommittedNotSupported:
1060
        raise tests.TestNotApplicable('Cannot store uncommitted changes.')
1061
1062
6538.1.2 by Aaron Bentley
Migrate tests to per_branch, support RemoteBranch.
1063
class TestUncommittedChanges(per_branch.TestCaseWithBranch):
1064
6772.3.1 by Jelmer Vernooij
Add supports_store_uncommitted.
1065
    def setUp(self):
1066
        super(TestUncommittedChanges, self).setUp()
1067
        if not self.branch_format.supports_store_uncommitted():
1068
            raise tests.TestNotApplicable(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1069
                'Branch format does not support store_uncommitted')
6772.3.1 by Jelmer Vernooij
Add supports_store_uncommitted.
1070
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1071
    def bind(self, branch, master):
1072
        try:
1073
            branch.bind(master)
1074
        except errors.UpgradeRequired:
1075
            raise tests.TestNotApplicable('Branch cannot be bound.')
1076
1077
    def test_store_uncommitted(self):
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
1078
        tree = self.make_branch_and_tree('b')
1079
        branch = tree.branch
1080
        creator = FakeShelfCreator(branch)
6538.1.31 by Aaron Bentley
Support foreign branches.
1081
        with skip_if_storing_uncommitted_unsupported():
1082
            self.assertIs(None, branch.get_unshelver(tree))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1083
        branch.store_uncommitted(creator)
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
1084
        self.assertIsNot(None, branch.get_unshelver(tree))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1085
1086
    def test_store_uncommitted_bound(self):
6538.1.31 by Aaron Bentley
Support foreign branches.
1087
        tree = self.make_branch_and_tree('b')
1088
        branch = tree.branch
1089
        master = self.make_branch('master')
1090
        self.bind(branch, master)
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
1091
        creator = FakeShelfCreator(tree.branch)
1092
        self.assertIs(None, tree.branch.get_unshelver(tree))
1093
        self.assertIs(None, master.get_unshelver(tree))
1094
        tree.branch.store_uncommitted(creator)
1095
        self.assertIsNot(None, master.get_unshelver(tree))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1096
1097
    def test_store_uncommitted_already_stored(self):
1098
        branch = self.make_branch('b')
6538.1.31 by Aaron Bentley
Support foreign branches.
1099
        with skip_if_storing_uncommitted_unsupported():
1100
            branch.store_uncommitted(FakeShelfCreator(branch))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1101
        self.assertRaises(errors.ChangesAlreadyStored,
6538.1.26 by Aaron Bentley
Remove get_uncommitted.
1102
                          branch.store_uncommitted, FakeShelfCreator(branch))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1103
1104
    def test_store_uncommitted_none(self):
1105
        branch = self.make_branch('b')
6538.1.31 by Aaron Bentley
Support foreign branches.
1106
        with skip_if_storing_uncommitted_unsupported():
1107
            branch.store_uncommitted(FakeShelfCreator(branch))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1108
        branch.store_uncommitted(None)
6538.1.24 by Aaron Bentley
Eliminate get_stored_uncommitted from API.
1109
        self.assertIs(None, branch.get_unshelver(None))
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1110
1111
    def test_get_unshelver(self):
1112
        tree = self.make_branch_and_tree('tree')
1113
        tree.commit('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1114
        self.build_tree_contents([('tree/file', b'contents1')])
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1115
        tree.add('file')
6538.1.31 by Aaron Bentley
Support foreign branches.
1116
        with skip_if_storing_uncommitted_unsupported():
1117
            tree.store_uncommitted()
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1118
        unshelver = tree.branch.get_unshelver(tree)
1119
        self.assertIsNot(None, unshelver)
1120
1121
    def test_get_unshelver_bound(self):
1122
        tree = self.make_branch_and_tree('tree')
1123
        tree.commit('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1124
        self.build_tree_contents([('tree/file', b'contents1')])
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1125
        tree.add('file')
6538.1.31 by Aaron Bentley
Support foreign branches.
1126
        with skip_if_storing_uncommitted_unsupported():
1127
            tree.store_uncommitted()
6538.1.23 by Aaron Bentley
Move uncommitted API to BzrBranch/RemoteBranch.
1128
        branch = self.make_branch('branch')
1129
        self.bind(branch, tree.branch)
1130
        unshelver = branch.get_unshelver(tree)
1131
        self.assertIsNot(None, unshelver)