/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3389.2.1 by John Arbash Meinel
Add code to 'bzr check' to detect when the mainline history is inconsistent.
1
# Copyright (C) 2005, 2006, 2007, 2008 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
19
import os
1185.31.39 by John Arbash Meinel
Replacing os.getcwdu() with osutils.getcwd(),
20
import sys
1442.1.62 by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions.
21
1878.1.3 by John Arbash Meinel
some test cleanups
22
from bzrlib import (
23
    branch,
24
    bzrdir,
25
    errors,
26
    gpg,
27
    urlutils,
28
    transactions,
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)
29
    remote,
1878.1.3 by John Arbash Meinel
some test cleanups
30
    repository,
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
31
    tests,
1878.1.3 by John Arbash Meinel
some test cleanups
32
    )
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
33
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
34
from bzrlib.delta import TreeDelta
1534.4.30 by Robert Collins
Test signature preservation on clone and upgrade.
35
from bzrlib.errors import (FileExists,
36
                           NoSuchRevision,
1534.4.5 by Robert Collins
Turn branch format.open into a factory.
37
                           NoSuchFile,
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
38
                           UninitializableFormat,
39
                           NotBranchError,
40
                           )
1185.31.39 by John Arbash Meinel
Replacing os.getcwdu() with osutils.getcwd(),
41
from bzrlib.osutils import getcwd
1836.3.1 by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION.
42
import bzrlib.revision
3445.2.2 by John Arbash Meinel
Move the test to a branch_implementations test
43
from bzrlib.symbol_versioning import deprecated_in
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
44
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
2418.5.2 by John Arbash Meinel
Move TestCaseWithBranch into branch_implementations from test_branch.py
45
from bzrlib.tests.branch_implementations import TestCaseWithBranch
2929.3.7 by Vincent Ladeuil
Rename bzrlib/test/HttpServer.py to bzrlib/tests/http_server.py and fix uses.
46
from bzrlib.tests.http_server import HttpServer
1260 by Martin Pool
- some updates for fetch/update function
47
from bzrlib.trace import mutter
1534.4.4 by Robert Collins
Make BzrBranchFormat.find_format take a transport not a url for efficiency.
48
from bzrlib.transport import get_transport
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
49
from bzrlib.transport.memory import MemoryServer
1534.4.30 by Robert Collins
Test signature preservation on clone and upgrade.
50
from bzrlib.upgrade import upgrade
1534.4.25 by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite.
51
from bzrlib.workingtree import WorkingTree
1092.2.25 by Robert Collins
support ghosts in commits
52
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
53
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
class TestTestCaseWithBranch(TestCaseWithBranch):
55
56
    def test_branch_format_matches_bzrdir_branch_format(self):
57
        bzrdir_branch_format = self.bzrdir_format.get_branch_format()
58
        self.assertIs(self.branch_format.__class__,
59
                      bzrdir_branch_format.__class__)
60
61
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
62
class TestBranch(TestCaseWithBranch):
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
63
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
64
    def test_create_tree_with_merge(self):
65
        tree = self.create_tree_with_merge()
3287.6.9 by Robert Collins
One last use of deprecated methods.
66
        tree.lock_read()
67
        self.addCleanup(tree.unlock)
68
        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.
69
        ancestry_graph = graph.get_parent_map(
70
            tree.branch.repository.all_revision_ids())
3287.6.9 by Robert Collins
One last use of deprecated methods.
71
        self.assertEqual({'rev-1':('null:',),
2625.8.1 by Robert Collins
LIBRARY API BREAKS:
72
                          'rev-2':('rev-1', ),
73
                          'rev-1.1.1':('rev-1', ),
74
                          'rev-3':('rev-2', 'rev-1.1.1', ),
2418.5.1 by John Arbash Meinel
Make a Branch helper which can create a very basic MemoryTree with history.
75
                         }, ancestry_graph)
76
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
77
    def test_revision_ids_are_utf8(self):
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
78
        wt = self.make_branch_and_tree('tree')
79
        wt.commit('f', rev_id='rev1')
80
        wt.commit('f', rev_id='rev2')
81
        wt.commit('f', rev_id='rev3')
82
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
83
        br = self.get_branch()
2249.5.17 by John Arbash Meinel
[merge] bzr.dev 2293 and resolve conflicts, but still broken
84
        br.fetch(wt.branch)
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
85
        br.set_revision_history(['rev1', 'rev2', 'rev3'])
86
        rh = br.revision_history()
87
        self.assertEqual(['rev1', 'rev2', 'rev3'], rh)
88
        for revision_id in rh:
89
            self.assertIsInstance(revision_id, str)
90
        last = br.last_revision()
91
        self.assertEqual('rev3', last)
92
        self.assertIsInstance(last, str)
2249.5.19 by John Arbash Meinel
Track through the new Branch6 code, and make sure revision ids are utf8
93
        revno, last = br.last_revision_info()
94
        self.assertEqual(3, revno)
95
        self.assertEqual('rev3', last)
96
        self.assertIsInstance(last, str)
2249.5.6 by John Arbash Meinel
Make sure Branch.revision_history() also works in utf-8 revision ids.
97
1260 by Martin Pool
- some updates for fetch/update function
98
    def test_fetch_revisions(self):
99
        """Test fetch-revision operation."""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
100
        wt = self.make_branch_and_tree('b1')
101
        b1 = wt.branch
2381.1.3 by Robert Collins
Review feedback.
102
        self.build_tree_contents([('b1/foo', 'hello')])
1534.4.25 by Robert Collins
Add a --transport parameter to the test suite to set the default transport to be used in the test suite.
103
        wt.add(['foo'], ['foo-id'])
104
        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
1260 by Martin Pool
- some updates for fetch/update function
105
2381.1.3 by Robert Collins
Review feedback.
106
        b2 = self.make_branch('b2')
1534.1.32 by Robert Collins
Deprecate direct use of fetch.Fetcher.
107
        self.assertEqual((1, []), b2.fetch(b1))
1260 by Martin Pool
- some updates for fetch/update function
108
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
109
        rev = b2.repository.get_revision('revision-1')
110
        tree = b2.repository.revision_tree('revision-1')
3015.2.1 by Robert Collins
Lock correctness in branch implementation tests.
111
        tree.lock_read()
112
        self.addCleanup(tree.unlock)
1534.1.32 by Robert Collins
Deprecate direct use of fetch.Fetcher.
113
        self.assertEqual(tree.get_file_text('foo-id'), 'hello')
1260 by Martin Pool
- some updates for fetch/update function
114
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
115
    def test_get_revision_delta(self):
116
        tree_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
117
        self.build_tree(['a/foo'])
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
118
        tree_a.add('foo', 'file1')
119
        tree_a.commit('rev1', rev_id='rev1')
2381.1.3 by Robert Collins
Review feedback.
120
        self.build_tree(['a/vla'])
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
121
        tree_a.add('vla', 'file2')
122
        tree_a.commit('rev2', rev_id='rev2')
123
124
        delta = tree_a.branch.get_revision_delta(1)
125
        self.assertIsInstance(delta, TreeDelta)
126
        self.assertEqual([('foo', 'file1', 'file')], delta.added)
127
        delta = tree_a.branch.get_revision_delta(2)
128
        self.assertIsInstance(delta, TreeDelta)
129
        self.assertEqual([('vla', 'file2', 'file')], delta.added)
130
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
131
    def get_unbalanced_tree_pair(self):
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
132
        """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.
133
        tree_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
134
        self.build_tree_contents([('a/b', 'b')])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
135
        tree_a.add('b')
136
        tree_a.commit("silly commit", rev_id='A')
137
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
        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.
139
        return tree_a, tree_b
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
140
141
    def get_balanced_branch_pair(self):
142
        """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.
143
        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.
144
        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.
145
        return tree_a, tree_b
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
146
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
147
    def test_clone_partial(self):
1393.1.23 by Martin Pool
- fix cloning of part of a branch
148
        """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.
149
        # TODO: RBC 20060208 test with a revision not on revision-history.
150
        #       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).
151
        # 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.
152
        wt_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
153
        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.
154
        wt_a.add(['one'])
155
        wt_a.commit('commit one', rev_id='1')
2381.1.3 by Robert Collins
Review feedback.
156
        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.
157
        wt_a.add(['two'])
158
        wt_a.commit('commit two', rev_id='2')
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
159
        # 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.
160
        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).
161
        wt_a.branch.repository.copy_content_into(repo_b)
162
        # wt_a might be a lightweight checkout, so get a hold of the actual
163
        # branch (because you can't do a partial clone of a lightweight
164
        # checkout).
165
        branch = wt_a.branch.bzrdir.open_branch()
166
        # Then make a branch where the new repository is, but specify a revision
167
        # ID.  The new branch's history will stop at the specified revision.
168
        br_b = branch.clone(repo_b.bzrdir, revision_id='1')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
169
        self.assertEqual('1', 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.
170
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
171
    def get_parented_branch(self):
172
        wt_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
173
        self.build_tree(['a/one'])
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
174
        wt_a.add(['one'])
175
        wt_a.commit('commit one', rev_id='1')
176
3489.2.4 by Andrew Bennetts
Fix all tests broken by fixing make_branch_and_tree.
177
        branch_b = wt_a.branch.bzrdir.sprout('b', revision_id='1').open_branch()
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
178
        self.assertEqual(wt_a.branch.base, branch_b.get_parent())
179
        return branch_b
180
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.
181
    def test_clone_branch_nickname(self):
182
        # test the nick name is preserved always
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
183
        raise 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.
184
185
    def test_clone_branch_parent(self):
186
        # 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)
187
        branch_b = self.get_parented_branch()
188
        repo_c = self.make_repository('c')
189
        branch_b.repository.copy_content_into(repo_c)
190
        branch_c = branch_b.clone(repo_c.bzrdir)
191
        self.assertNotEqual(None, branch_c.get_parent())
192
        self.assertEqual(branch_b.get_parent(), branch_c.get_parent())
193
194
        # We can also set a specific parent, and it should be honored
195
        random_parent = 'http://bazaar-vcs.org/path/to/branch'
196
        branch_b.set_parent(random_parent)
197
        repo_d = self.make_repository('d')
198
        branch_b.repository.copy_content_into(repo_d)
199
        branch_d = branch_b.clone(repo_d.bzrdir)
200
        self.assertEqual(random_parent, branch_d.get_parent())
201
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
202
    def test_submit_branch(self):
203
        """Submit location can be queried and set"""
204
        branch = self.make_branch('branch')
205
        self.assertEqual(branch.get_submit_branch(), None)
206
        branch.set_submit_branch('sftp://example.com')
207
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.com')
208
        branch.set_submit_branch('sftp://example.net')
209
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.net')
1393.1.23 by Martin Pool
- fix cloning of part of a branch
210
        
1551.12.44 by Aaron Bentley
Add (set|get)_public_branch
211
    def test_public_branch(self):
212
        """public location can be queried and set"""
213
        branch = self.make_branch('branch')
214
        self.assertEqual(branch.get_public_branch(), None)
215
        branch.set_public_branch('sftp://example.com')
216
        self.assertEqual(branch.get_public_branch(), 'sftp://example.com')
217
        branch.set_public_branch('sftp://example.net')
218
        self.assertEqual(branch.get_public_branch(), 'sftp://example.net')
219
        branch.set_public_branch(None)
220
        self.assertEqual(branch.get_public_branch(), None)
221
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.
222
    def test_record_initial_ghost(self):
223
        """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.
224
        wt = self.make_branch_and_tree('.')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
225
        wt.set_parent_ids(['non:existent@rev--ision--0--2'],
226
            allow_leftmost_as_ghost=True)
3240.1.3 by Aaron Bentley
Use Graph to generate revision_history
227
        self.assertEqual(['non:existent@rev--ision--0--2'],
228
            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.
229
        rev_id = wt.commit('commit against a ghost first parent.')
230
        rev = wt.branch.repository.get_revision(rev_id)
231
        self.assertEqual(rev.parent_ids, ['non:existent@rev--ision--0--2'])
1092.2.25 by Robert Collins
support ghosts in commits
232
        # parent_sha1s is not populated now, WTF. rbc 20051003
233
        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.
234
235
    def test_record_two_ghosts(self):
236
        """Recording with all ghosts works."""
237
        wt = self.make_branch_and_tree('.')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
238
        wt.set_parent_ids([
239
                'foo@azkhazan-123123-abcabc',
240
                'wibble@fofof--20050401--1928390812',
241
            ],
242
            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.
243
        rev_id = wt.commit("commit from ghost base with one merge")
244
        # the revision should have been committed with two parents
245
        rev = wt.branch.repository.get_revision(rev_id)
246
        self.assertEqual(['foo@azkhazan-123123-abcabc',
247
            'wibble@fofof--20050401--1928390812'],
248
            rev.parent_ids)
1092.2.25 by Robert Collins
support ghosts in commits
249
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
250
    def test_bad_revision(self):
1534.4.28 by Robert Collins
first cut at merge from integration.
251
        self.assertRaises(errors.InvalidRevisionId,
252
                          self.get_branch().repository.get_revision,
253
                          None)
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
254
1092.2.28 by Robert Collins
reenable test of fetching a branch with ghosts
255
# TODO 20051003 RBC:
1092.2.25 by Robert Collins
support ghosts in commits
256
# compare the gpg-to-sign info for a commit with a ghost and 
257
#     an identical tree without a ghost
258
# fetch missing should rewrite the TOC of weaves to list newly available parents.
1393.1.9 by Martin Pool
- tidy up test assertion
259
        
1442.1.60 by Robert Collins
gpg sign commits if the policy says we need to
260
    def test_sign_existing_revision(self):
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.
261
        wt = self.make_branch_and_tree('.')
262
        branch = wt.branch
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
263
        wt.commit("base", allow_pointless=True, rev_id='A')
1442.1.60 by Robert Collins
gpg sign commits if the policy says we need to
264
        from bzrlib.testament import Testament
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
265
        strategy = gpg.LoopbackGPGStrategy(None)
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
266
        branch.repository.lock_write()
267
        branch.repository.start_write_group()
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
268
        branch.repository.sign_revision('A', strategy)
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
269
        branch.repository.commit_write_group()
270
        branch.repository.unlock()
1551.12.36 by Aaron Bentley
Fix failing tests
271
        self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
272
                         Testament.from_revision(branch.repository,
273
                         'A').as_short_text() +
1551.12.52 by Aaron Bentley
speling fix
274
                         '-----END PSEUDO-SIGNED CONTENT-----\n',
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
275
                         branch.repository.get_signature_text('A'))
1442.1.60 by Robert Collins
gpg sign commits if the policy says we need to
276
1442.1.62 by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions.
277
    def test_store_signature(self):
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
278
        wt = self.make_branch_and_tree('.')
279
        branch = wt.branch
3015.2.3 by Robert Collins
Use write groups around revision signature tests for branch.
280
        branch.lock_write()
281
        try:
282
            branch.repository.start_write_group()
283
            try:
284
                branch.repository.store_revision_signature(
285
                    gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
286
            except:
287
                branch.repository.abort_write_group()
288
                raise
289
            else:
290
                branch.repository.commit_write_group()
291
        finally:
292
            branch.unlock()
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.
293
        # A signature without a revision should not be accessible.
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
294
        self.assertRaises(errors.NoSuchRevision,
295
                          branch.repository.has_signature_for_revision_id,
296
                          'A')
297
        wt.commit("base", allow_pointless=True, rev_id='A')
1551.12.36 by Aaron Bentley
Fix failing tests
298
        self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n'
1551.12.52 by Aaron Bentley
speling fix
299
                         'FOO-----END PSEUDO-SIGNED CONTENT-----\n',
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
300
                         branch.repository.get_signature_text('A'))
1469 by Robert Collins
Change Transport.* to work with URL's.
301
1534.4.30 by Robert Collins
Test signature preservation on clone and upgrade.
302
    def test_branch_keeps_signatures(self):
303
        wt = self.make_branch_and_tree('source')
304
        wt.commit('A', allow_pointless=True, rev_id='A')
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
305
        repo = wt.branch.repository
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
306
        repo.lock_write()
307
        repo.start_write_group()
2818.4.2 by Robert Collins
Review feedback.
308
        repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
309
        repo.commit_write_group()
310
        repo.unlock()
1534.4.30 by Robert Collins
Test signature preservation on clone and upgrade.
311
        #FIXME: clone should work to urls,
312
        # wt.clone should work to disks.
313
        self.build_tree(['target/'])
2018.5.94 by Andrew Bennetts
Various small changes in aid of making tests pass (including deleting one invalid test).
314
        d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
315
        self.assertEqual(repo.get_signature_text('A'),
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
316
                         d2.open_repository().get_signature_text('A'))
1534.4.30 by Robert Collins
Test signature preservation on clone and upgrade.
317
3445.2.2 by John Arbash Meinel
Move the test to a branch_implementations test
318
    def test_missing_revisions(self):
319
        t1 = self.make_branch_and_tree('b1')
320
        rev1 = t1.commit('one')
321
        t2 = t1.bzrdir.sprout('b2').open_workingtree()
322
        rev2 = t1.commit('two')
323
        rev3 = t1.commit('three')
324
325
        self.assertEqual([rev2, rev3],
326
            self.applyDeprecated(deprecated_in((1, 6, 0)),
327
            t2.branch.missing_revisions, t1.branch))
328
329
        self.assertEqual([],
330
            self.applyDeprecated(deprecated_in((1, 6, 0)),
331
            t2.branch.missing_revisions, t1.branch, stop_revision=1))
332
        self.assertEqual([rev2],
333
            self.applyDeprecated(deprecated_in((1, 6, 0)),
334
            t2.branch.missing_revisions, t1.branch, stop_revision=2))
335
        self.assertEqual([rev2, rev3],
336
            self.applyDeprecated(deprecated_in((1, 6, 0)),
337
            t2.branch.missing_revisions, t1.branch, stop_revision=3))
338
339
        self.assertRaises(errors.NoSuchRevision,
340
            self.applyDeprecated, deprecated_in((1, 6, 0)),
341
            t2.branch.missing_revisions, t1.branch, stop_revision=4)
342
343
        rev4 = t2.commit('four')
344
        self.assertRaises(errors.DivergedBranches,
345
            self.applyDeprecated, deprecated_in((1, 6, 0)),
346
            t2.branch.missing_revisions, t1.branch)
347
1185.35.11 by Aaron Bentley
Added support for branch nicks
348
    def test_nicks(self):
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.
349
        """Test explicit and implicit branch nicknames.
350
        
351
        Nicknames are implicitly the name of the branch's directory, unless an
352
        explicit nickname is set.  That is, an explicit nickname always
353
        overrides the implicit one.
354
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
355
        t = get_transport(self.get_url())
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
356
        branch = self.make_branch('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.
357
        # The nick will be 'bzr.dev', because there is no explicit nick set.
1185.35.11 by Aaron Bentley
Added support for branch nicks
358
        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.
359
        # Move the branch to a different directory, 'bzr.ab'.  Now that branch
360
        # 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.
361
        t.move('bzr.dev', 'bzr.ab')
362
        branch = Branch.open(self.get_url('bzr.ab'))
1185.35.11 by Aaron Bentley
Added support for branch nicks
363
        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.
364
        # Set the branch nick explicitly.  This will ensure there's a branch
365
        # config file in the branch.
366
        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)
367
        if not isinstance(branch, remote.RemoteBranch):
3407.2.8 by Martin Pool
Deprecate LockableFiles.controlfilename
368
            self.failUnless(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.
369
        # Because the nick has been set explicitly, the nick is now always
370
        # "Aaron's branch", regardless of directory name.
1185.35.11 by Aaron Bentley
Added support for branch nicks
371
        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.
372
        t.move('bzr.ab', 'integration')
373
        branch = Branch.open(self.get_url('integration'))
1185.35.11 by Aaron Bentley
Added support for branch nicks
374
        self.assertEqual(branch.nick, "Aaron's branch")
1185.35.12 by Aaron Bentley
Got writes of existing tree configs working.
375
        branch.nick = u"\u1234"
376
        self.assertEqual(branch.nick, u"\u1234")
1185.35.11 by Aaron Bentley
Added support for branch nicks
377
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
378
    def test_commit_nicks(self):
379
        """Nicknames are committed to the revision"""
380
        wt = self.make_branch_and_tree('bzr.dev')
381
        branch = wt.branch
382
        branch.nick = "My happy branch"
383
        wt.commit('My commit respect da nick.')
384
        committed = branch.repository.get_revision(branch.last_revision())
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
385
        self.assertEqual(committed.properties["branch-nick"],
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
386
                         "My happy branch")
387
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
388
    def test_create_open_branch_uses_repository(self):
389
        try:
390
            repo = self.make_repository('.', shared=True)
391
        except errors.IncompatibleFormat:
392
            return
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.
393
        child_transport = repo.bzrdir.root_transport.clone('child')
394
        child_transport.mkdir('.')
395
        child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
396
        try:
397
            child_branch = self.branch_format.initialize(child_dir)
398
        except errors.UninitializableFormat:
399
            # branch references are not default init'able.
400
            return
401
        self.assertEqual(repo.bzrdir.root_transport.base,
402
                         child_branch.repository.bzrdir.root_transport.base)
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
403
        child_branch = branch.Branch.open(self.get_url('child'))
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
404
        self.assertEqual(repo.bzrdir.root_transport.base,
405
                         child_branch.repository.bzrdir.root_transport.base)
406
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
407
    def test_format_description(self):
408
        tree = self.make_branch_and_tree('tree')
409
        text = tree.branch._format.get_format_description()
410
        self.failUnless(len(text))
411
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
412
    def test_get_commit_builder(self):
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
413
        branch = self.make_branch(".")
414
        branch.lock_write()
415
        builder = branch.get_commit_builder([])
416
        self.assertIsInstance(builder, repository.CommitBuilder)
417
        branch.repository.commit_write_group()
418
        branch.unlock()
1740.3.1 by Jelmer Vernooij
Introduce and use CommitBuilder objects.
419
1792.1.1 by Robert Collins
Factor out revision-history synthesis to make it reusable as Branch.generate_revision_history.
420
    def test_generate_revision_history(self):
421
        """Create a fake revision history easily."""
422
        tree = self.make_branch_and_tree('.')
423
        rev1 = tree.commit('foo')
424
        orig_history = tree.branch.revision_history()
425
        rev2 = tree.commit('bar', allow_pointless=True)
426
        tree.branch.generate_revision_history(rev1)
427
        self.assertEqual(orig_history, tree.branch.revision_history())
428
1836.3.1 by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION.
429
    def test_generate_revision_history_NULL_REVISION(self):
430
        tree = self.make_branch_and_tree('.')
431
        rev1 = tree.commit('foo')
432
        tree.branch.generate_revision_history(bzrlib.revision.NULL_REVISION)
433
        self.assertEqual([], tree.branch.revision_history())
434
1551.8.6 by Aaron Bentley
Rename test
435
    def test_create_checkout(self):
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
436
        tree_a = self.make_branch_and_tree('a')
437
        branch_a = tree_a.branch
1551.8.5 by Aaron Bentley
Change name to create_checkout
438
        checkout_b = branch_a.create_checkout('b')
2598.5.10 by Aaron Bentley
Return NULL_REVISION instead of None for the null revision
439
        self.assertEqual('null:', checkout_b.last_revision())
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
440
        checkout_b.commit('rev1', rev_id='rev1')
441
        self.assertEqual('rev1', branch_a.last_revision())
442
        self.assertNotEqual(checkout_b.branch.base, branch_a.base)
443
1551.8.5 by Aaron Bentley
Change name to create_checkout
444
        checkout_c = branch_a.create_checkout('c', lightweight=True)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
445
        self.assertEqual('rev1', checkout_c.last_revision())
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
446
        checkout_c.commit('rev2', rev_id='rev2')
447
        self.assertEqual('rev2', branch_a.last_revision())
448
        self.assertEqual(checkout_c.branch.base, branch_a.base)
449
450
        os.mkdir('d')
1551.8.5 by Aaron Bentley
Change name to create_checkout
451
        checkout_d = branch_a.create_checkout('d', lightweight=True)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
452
        self.assertEqual('rev2', checkout_d.last_revision())
1551.8.3 by Aaron Bentley
Make create_checkout_convenience a Branch method
453
        os.mkdir('e')
1551.8.5 by Aaron Bentley
Change name to create_checkout
454
        checkout_e = branch_a.create_checkout('e')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
455
        self.assertEqual('rev2', checkout_e.last_revision())
1425 by Robert Collins
merge from Aaron - unbreaks open_containing and the fetch progress bar
456
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
457
    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
458
        """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
459
        tree_a = self.make_branch_and_tree('a')
460
        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.
461
        # open the branch via a readonly transport
462
        source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
1997.1.4 by Robert Collins
``bzr checkout --lightweight`` now operates on readonly branches as well
463
        # sanity check that the test will be valid
464
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
465
            source_branch.lock_write)
466
        checkout = source_branch.create_checkout('c', lightweight=True)
467
        self.assertEqual(rev_id, checkout.last_revision())
468
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
469
    def test_create_anonymous_heavyweight_checkout(self):
470
        """A regular checkout from a readonly branch should succeed."""
471
        tree_a = self.make_branch_and_tree('a')
472
        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.
473
        # open the branch via a readonly transport
474
        source_branch = bzrlib.branch.Branch.open(self.get_readonly_url('a'))
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
475
        # sanity check that the test will be valid
476
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
477
            source_branch.lock_write)
478
        checkout = source_branch.create_checkout('c')
479
        self.assertEqual(rev_id, checkout.last_revision())
480
2018.12.1 by Andrew Bennetts
Add TestBranch.test_set_revision_history
481
    def test_set_revision_history(self):
2018.5.97 by Andrew Bennetts
Fix more tests.
482
        tree = self.make_branch_and_tree('a')
483
        tree.commit('a commit', rev_id='rev1')
484
        br = tree.branch
2018.12.1 by Andrew Bennetts
Add TestBranch.test_set_revision_history
485
        br.set_revision_history(["rev1"])
486
        self.assertEquals(br.revision_history(), ["rev1"])
487
        br.set_revision_history([])
488
        self.assertEquals(br.revision_history(), [])
489
1551.8.4 by Aaron Bentley
Tweak import style
490
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
491
class ChrootedTests(TestCaseWithBranch):
492
    """A support class that provides readonly urls outside the local namespace.
493
494
    This is done by checking if self.transport_server is a MemoryServer. if it
495
    is then we are chrooted already, if it is not then an HttpServer is used
496
    for readonly urls.
497
    """
498
499
    def setUp(self):
500
        super(ChrootedTests, self).setUp()
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
501
        if not self.vfs_transport_factory == MemoryServer:
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
502
            self.transport_readonly_server = HttpServer
1425 by Robert Collins
merge from Aaron - unbreaks open_containing and the fetch progress bar
503
1185.12.18 by Aaron Bentley
Fixed error handling when NotBranch on HTTP
504
    def test_open_containing(self):
505
        self.assertRaises(NotBranchError, 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.
506
                          self.get_readonly_url(''))
1185.12.18 by Aaron Bentley
Fixed error handling when NotBranch on HTTP
507
        self.assertRaises(NotBranchError, 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.
508
                          self.get_readonly_url('g/p/q'))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
509
        branch = self.make_branch('.')
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
510
        branch, relpath = Branch.open_containing(self.get_readonly_url(''))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
511
        self.assertEqual('', relpath)
1534.4.11 by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test.
512
        branch, relpath = Branch.open_containing(self.get_readonly_url('g/p/q'))
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
513
        self.assertEqual('g/p/q', relpath)
2929.3.21 by Vincent Ladeuil
Merge bzr.dev, resolve conflicts.
514
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
515
516
class InstrumentedTransaction(object):
517
518
    def finish(self):
519
        self.calls.append('finish')
520
521
    def __init__(self):
522
        self.calls = []
523
524
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
525
class TestDecorator(object):
526
527
    def __init__(self):
528
        self._calls = []
529
530
    def lock_read(self):
531
        self._calls.append('lr')
532
533
    def lock_write(self):
534
        self._calls.append('lw')
535
536
    def unlock(self):
537
        self._calls.append('ul')
538
539
    @needs_read_lock
540
    def do_with_read(self):
541
        return 1
542
543
    @needs_read_lock
544
    def except_with_read(self):
545
        raise RuntimeError
546
547
    @needs_write_lock
548
    def do_with_write(self):
549
        return 2
550
551
    @needs_write_lock
552
    def except_with_write(self):
553
        raise RuntimeError
554
555
556
class TestDecorators(TestCase):
557
558
    def test_needs_read_lock(self):
559
        branch = TestDecorator()
560
        self.assertEqual(1, branch.do_with_read())
561
        self.assertEqual(['lr', 'ul'], branch._calls)
562
563
    def test_excepts_in_read_lock(self):
564
        branch = TestDecorator()
565
        self.assertRaises(RuntimeError, branch.except_with_read)
566
        self.assertEqual(['lr', 'ul'], branch._calls)
567
568
    def test_needs_write_lock(self):
569
        branch = TestDecorator()
570
        self.assertEqual(2, branch.do_with_write())
571
        self.assertEqual(['lw', 'ul'], branch._calls)
572
573
    def test_excepts_in_write_lock(self):
574
        branch = TestDecorator()
575
        self.assertRaises(RuntimeError, branch.except_with_write)
576
        self.assertEqual(['lw', 'ul'], branch._calls)
577
578
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
579
class TestBranchPushLocations(TestCaseWithBranch):
580
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
581
    def test_get_push_location_unset(self):
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
582
        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.
583
584
    def test_get_push_location_exact(self):
1770.2.2 by Aaron Bentley
Rename branches.conf to locations.conf
585
        from bzrlib.config import (locations_config_filename,
1185.31.43 by John Arbash Meinel
Reintroduced ensure_config_dir_exists() for sftp
586
                                   ensure_config_dir_exists)
587
        ensure_config_dir_exists()
1770.2.2 by Aaron Bentley
Rename branches.conf to locations.conf
588
        fn = locations_config_filename()
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
589
        open(fn, 'wt').write(("[%s]\n"
590
                                  "push_location=foo\n" %
591
                                  self.get_branch().base[:-1]))
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
592
        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.
593
594
    def test_set_push_location(self):
1878.1.3 by John Arbash Meinel
some test cleanups
595
        branch = self.get_branch()
596
        branch.set_push_location('foo')
2230.3.3 by Aaron Bentley
Add more config testing
597
        self.assertEqual('foo', branch.get_push_location())
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
598
599
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
600
class TestFormat(TestCaseWithBranch):
601
    """Tests for the format itself."""
602
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
603
    def test_get_reference(self):
604
        """get_reference on all regular branches should return None."""
605
        if not self.branch_format.is_supported():
606
            # unsupported formats are not loopback testable
607
            # because the default open will not open them and
608
            # they may not be initializable.
609
            return
610
        made_branch = self.make_branch('.')
611
        self.assertEqual(None,
612
            made_branch._format.get_reference(made_branch.bzrdir))
613
3078.2.7 by Ian Clatworthy
added smoke test for set_reference
614
    def test_set_reference(self):
615
        """set_reference on all regular branches should be callable."""
616
        if not self.branch_format.is_supported():
617
            # unsupported formats are not loopback testable
618
            # because the default open will not open them and
619
            # they may not be initializable.
620
            return
621
        this_branch = self.make_branch('this')
622
        other_branch = self.make_branch('other')
623
        try:
624
            this_branch._format.set_reference(this_branch.bzrdir, other_branch)
625
        except NotImplementedError:
626
            # that's ok
627
            pass
628
        else:
629
            ref = this_branch._format.get_reference(this_branch.bzrdir)
630
            self.assertEqual(ref, other_branch.base)
631
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
632
    def test_format_initialize_find_open(self):
633
        # 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.
634
        if not self.branch_format.is_supported():
635
            # unsupported formats are not loopback testable
636
            # because the default open will not open them and
637
            # they may not be initializable.
638
            return
639
        # supported formats must be able to init and open
1534.4.12 by Robert Collins
Tweak formats implementation test to exercise readonly and readwrite transports.
640
        t = get_transport(self.get_url())
641
        readonly_t = get_transport(self.get_readonly_url())
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
642
        made_branch = self.make_branch('.')
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
643
        self.failUnless(isinstance(made_branch, branch.Branch))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
644
645
        # find it via bzrdir opening:
646
        opened_control = bzrdir.BzrDir.open(readonly_t.base)
647
        direct_opened_branch = opened_control.open_branch()
648
        self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
649
        self.assertEqual(opened_control, direct_opened_branch.bzrdir)
650
        self.failUnless(isinstance(direct_opened_branch._format,
651
                        self.branch_format.__class__))
652
653
        # find it via Branch.open
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
654
        opened_branch = branch.Branch.open(readonly_t.base)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
655
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
656
        self.assertEqual(made_branch._format.__class__,
657
                         opened_branch._format.__class__)
658
        # if it has a unique id string, can we probe for it ?
659
        try:
660
            self.branch_format.get_format_string()
661
        except NotImplementedError:
662
            return
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
663
        self.assertEqual(self.branch_format,
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
664
                         opened_control.find_branch_format())
1711.8.1 by John Arbash Meinel
Branch.lock_read/lock_write/unlock should handle failures
665
2230.3.7 by Aaron Bentley
Fix binding return values
666
2230.3.6 by Aaron Bentley
work in progress bind stuff
667
class TestBound(TestCaseWithBranch):
668
669
    def test_bind_unbind(self):
670
        branch = self.make_branch('1')
671
        branch2 = self.make_branch('2')
672
        try:
673
            branch.bind(branch2)
674
        except errors.UpgradeRequired:
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
675
            raise tests.TestNotApplicable('Format does not support binding')
2230.3.7 by Aaron Bentley
Fix binding return values
676
        self.assertTrue(branch.unbind())
677
        self.assertFalse(branch.unbind())
2230.3.6 by Aaron Bentley
work in progress bind stuff
678
        self.assertIs(None, branch.get_bound_location())
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
679
680
    def test_old_bound_location(self):
681
        branch = self.make_branch('branch1')
682
        try:
683
            self.assertIs(None, branch.get_old_bound_location())
684
        except errors.UpgradeRequired:
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
685
            raise tests.TestNotApplicable(
686
                    'Format does not store old bound locations')
2230.3.31 by Aaron Bentley
Implement re-binding previously-bound branches
687
        branch2 = self.make_branch('branch2')
688
        branch.bind(branch2)
689
        self.assertIs(None, branch.get_old_bound_location())
690
        branch.unbind()
691
        self.assertContainsRe(branch.get_old_bound_location(), '\/branch2\/$')
2230.3.32 by Aaron Bentley
Implement strict history policy
692
3099.1.1 by John Arbash Meinel
Fix bug #175337, bzr bind shouldn't check the ancestry
693
    def test_bind_diverged(self):
694
        tree_a = self.make_branch_and_tree('tree_a')
695
        tree_a.commit('rev1a')
696
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
697
        tree_a.commit('rev2a')
698
        tree_b.commit('rev2b')
699
        try:
700
            tree_b.branch.bind(tree_a.branch)
701
        except errors.UpgradeRequired:
702
            raise tests.TestNotApplicable('Format does not support binding')
703
2230.3.32 by Aaron Bentley
Implement strict history policy
704
705
class TestStrict(TestCaseWithBranch):
706
707
    def test_strict_history(self):
708
        tree1 = self.make_branch_and_tree('tree1')
709
        try:
2230.3.40 by Aaron Bentley
Rename strict_revision_history to append_revisions_only
710
            tree1.branch.set_append_revisions_only(True)
2230.3.32 by Aaron Bentley
Implement strict history policy
711
        except errors.UpgradeRequired:
712
            raise TestSkipped('Format does not support strict history')
713
        tree1.commit('empty commit')
714
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
715
        tree2.commit('empty commit 2')
716
        tree1.pull(tree2.branch)
717
        tree1.commit('empty commit 3')
718
        tree2.commit('empty commit 4')
719
        self.assertRaises(errors.DivergedBranches, tree1.pull, tree2.branch)
720
        tree2.merge_from_branch(tree1.branch)
721
        tree2.commit('empty commit 5')
2230.3.40 by Aaron Bentley
Rename strict_revision_history to append_revisions_only
722
        self.assertRaises(errors.AppendRevisionsOnlyViolation, tree1.pull,
2230.3.32 by Aaron Bentley
Implement strict history policy
723
                          tree2.branch)
724
        tree3 = tree1.bzrdir.sprout('tree3').open_workingtree()
725
        tree3.merge_from_branch(tree2.branch)
726
        tree3.commit('empty commit 6')
727
        tree2.pull(tree3.branch)