105
115
tree = b2.repository.revision_tree('revision-1')
106
116
eq(tree.get_file_text('foo-id'), 'hello')
108
def test_revision_tree(self):
109
b1 = self.get_branch()
110
wt = WorkingTree.create(b1, '.')
111
wt.commit('lala!', rev_id='revision-1', allow_pointless=True)
112
tree = b1.repository.revision_tree('revision-1')
113
tree = b1.repository.revision_tree(None)
114
self.assertEqual(len(tree.list_files()), 0)
115
tree = b1.repository.revision_tree(NULL_REVISION)
116
self.assertEqual(len(tree.list_files()), 0)
118
118
def get_unbalanced_tree_pair(self):
119
119
"""Return two branches, a and b, with one file in a."""
120
120
get_transport(self.get_url()).mkdir('a')
121
br_a = self.make_branch('a')
122
tree_a = WorkingTree.create(br_a, 'a')
121
tree_a = self.make_branch_and_tree('a')
123
122
file('a/b', 'wb').write('b')
125
124
tree_a.commit("silly commit", rev_id='A')
127
126
get_transport(self.get_url()).mkdir('b')
128
br_b = self.make_branch('b')
129
tree_b = WorkingTree.create(br_b, 'b')
127
tree_b = self.make_branch_and_tree('b')
130
128
return tree_a, tree_b
132
130
def get_balanced_branch_pair(self):
133
131
"""Returns br_a, br_b as with one commit in a, and b has a's stores."""
134
132
tree_a, tree_b = self.get_unbalanced_tree_pair()
135
tree_a.branch.push_stores(tree_b.branch)
133
tree_b.branch.repository.fetch(tree_a.branch.repository)
136
134
return tree_a, tree_b
138
def test_push_stores(self):
139
"""Copy the stores from one branch to another"""
140
tree_a, tree_b = self.get_unbalanced_tree_pair()
143
# ensure the revision is missing.
144
self.assertRaises(NoSuchRevision, br_b.repository.get_revision,
145
br_a.revision_history()[0])
146
br_a.push_stores(br_b)
147
# check that b now has all the data from a's first commit.
148
rev = br_b.repository.get_revision(br_a.revision_history()[0])
149
tree = br_b.repository.revision_tree(br_a.revision_history()[0])
151
if tree.inventory[file_id].kind == "file":
152
tree.get_file(file_id).read()
154
136
def test_clone_branch(self):
155
137
"""Copy the stores from one branch to another"""
156
138
tree_a, tree_b = self.get_balanced_branch_pair()
157
139
tree_b.commit("silly commit")
159
br_c = tree_a.branch.clone('c', basis_branch=tree_b.branch)
141
# this fails to test that the history from a was not used.
142
dir_c = tree_a.bzrdir.clone('c', basis=tree_b.bzrdir)
160
143
self.assertEqual(tree_a.branch.revision_history(),
161
br_c.revision_history())
144
dir_c.open_branch().revision_history())
163
146
def test_clone_partial(self):
164
147
"""Copy only part of the history of a branch."""
165
get_transport(self.get_url()).mkdir('a')
166
br_a = self.make_branch('a')
167
wt = WorkingTree.create(br_a, "a")
168
self.build_tree(['a/one'])
170
wt.commit('commit one', rev_id='u@d-1')
171
self.build_tree(['a/two'])
173
wt.commit('commit two', rev_id='u@d-2')
174
br_b = br_a.clone('b', revision='u@d-1')
175
self.assertEqual(br_b.last_revision(), 'u@d-1')
176
self.assertTrue(os.path.exists('b/one'))
177
self.assertFalse(os.path.exists('b/two'))
148
# TODO: RBC 20060208 test with a revision not on revision-history.
149
# what should that behaviour be ? Emailed the list.
150
wt_a = self.make_branch_and_tree('a')
151
self.build_tree(['a/one'])
153
wt_a.commit('commit one', rev_id='1')
154
self.build_tree(['a/two'])
156
wt_a.commit('commit two', rev_id='2')
157
repo_b = self.make_repository('b')
158
wt_a.bzrdir.open_repository().copy_content_into(repo_b)
159
br_b = wt_a.bzrdir.open_branch().clone(repo_b.bzrdir, revision_id='1')
160
self.assertEqual(br_b.last_revision(), '1')
162
def test_sprout_partial(self):
163
# test sprouting with a prefix of the revision-history.
164
# also needs not-on-revision-history behaviour defined.
165
wt_a = self.make_branch_and_tree('a')
166
self.build_tree(['a/one'])
168
wt_a.commit('commit one', rev_id='1')
169
self.build_tree(['a/two'])
171
wt_a.commit('commit two', rev_id='2')
172
repo_b = self.make_repository('b')
173
wt_a.bzrdir.open_repository().copy_content_into(repo_b)
174
br_b = wt_a.bzrdir.open_branch().sprout(repo_b.bzrdir, revision_id='1')
175
self.assertEqual(br_b.last_revision(), '1')
177
def test_clone_branch_nickname(self):
178
# test the nick name is preserved always
179
raise TestSkipped('XXX branch cloning is not yet tested..')
181
def test_clone_branch_parent(self):
182
# test the parent is preserved always
183
raise TestSkipped('XXX branch cloning is not yet tested..')
185
def test_sprout_branch_nickname(self):
186
# test the nick name is reset always
187
raise TestSkipped('XXX branch sprouting is not yet tested..')
189
def test_sprout_branch_parent(self):
190
source = self.make_branch('source')
191
target = source.bzrdir.sprout(self.get_url('target')).open_branch()
192
self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
179
194
def test_record_initial_ghost_merge(self):
180
195
"""A pending merge with no revision present is still a merge."""
181
branch = self.get_branch()
182
wt = WorkingTree.create(branch, ".")
196
wt = self.make_branch_and_tree('.')
183
198
wt.add_pending_merge('non:existent@rev--ision--0--2')
184
199
wt.commit('pretend to merge nonexistent-revision', rev_id='first')
185
200
rev = branch.repository.get_revision(branch.last_revision())
511
518
# supported formats must be able to init and open
512
519
t = get_transport(self.get_url())
513
520
readonly_t = get_transport(self.get_readonly_url())
514
made_branch = self.branch_format.initialize(t.base)
515
self.failUnless(isinstance(made_branch, branch.Branch))
521
made_branch = self.make_branch('.')
522
self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
524
# find it via bzrdir opening:
525
opened_control = bzrdir.BzrDir.open(readonly_t.base)
526
direct_opened_branch = opened_control.open_branch()
527
self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
528
self.assertEqual(opened_control, direct_opened_branch.bzrdir)
529
self.failUnless(isinstance(direct_opened_branch._format,
530
self.branch_format.__class__))
532
# find it via Branch.open
533
opened_branch = bzrlib.branch.Branch.open(readonly_t.base)
534
self.failUnless(isinstance(opened_branch, made_branch.__class__))
535
self.assertEqual(made_branch._format.__class__,
536
opened_branch._format.__class__)
537
# if it has a unique id string, can we probe for it ?
539
self.branch_format.get_format_string()
540
except NotImplementedError:
516
542
self.assertEqual(self.branch_format,
517
branch.BzrBranchFormat.find_format(readonly_t))
518
direct_opened_branch = self.branch_format.open(readonly_t)
519
opened_branch = branch.Branch.open(t.base)
520
self.assertEqual(made_branch._branch_format,
521
opened_branch._branch_format)
522
self.assertEqual(direct_opened_branch._branch_format,
523
opened_branch._branch_format)
524
self.failUnless(isinstance(opened_branch, branch.Branch))
526
def test_open_not_branch(self):
527
self.assertRaises(NoSuchFile,
528
self.branch_format.open,
529
get_transport(self.get_readonly_url()))
543
bzrlib.branch.BranchFormat.find_format(opened_control))