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