20
20
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
21
from bzrlib.clone import copy_branch
22
21
from bzrlib.commit import commit
23
22
import bzrlib.errors as errors
24
23
from bzrlib.errors import NoSuchRevision, UnlistableBranch, NotBranchError
59
58
f = Fetcher(from_branch=b1, to_branch=b2)
60
59
eq = self.assertEquals
61
60
eq(f.count_copied, 1)
62
eq(f.last_revision, 'revision-1')
61
eq(f._last_revision, 'revision-1')
64
rev = b2.get_revision('revision-1')
65
tree = b2.revision_tree('revision-1')
63
rev = b2.repository.get_revision('revision-1')
64
tree = b2.repository.revision_tree('revision-1')
66
65
eq(tree.get_file_text('foo-id'), 'hello')
68
67
def test_revision_tree(self):
69
68
b1 = Branch.initialize(u'.')
70
69
b1.working_tree().commit('lala!', rev_id='revision-1', allow_pointless=True)
71
tree = b1.revision_tree('revision-1')
72
tree = b1.revision_tree(None)
70
tree = b1.repository.revision_tree('revision-1')
71
tree = b1.repository.revision_tree(None)
73
72
self.assertEqual(len(tree.list_files()), 0)
74
tree = b1.revision_tree(NULL_REVISION)
73
tree = b1.repository.revision_tree(NULL_REVISION)
75
74
self.assertEqual(len(tree.list_files()), 0)
77
76
def get_unbalanced_branch_pair(self):
95
94
"""Copy the stores from one branch to another"""
96
95
br_a, br_b = self.get_unbalanced_branch_pair()
97
96
# ensure the revision is missing.
98
self.assertRaises(NoSuchRevision, br_b.get_revision,
97
self.assertRaises(NoSuchRevision, br_b.repository.get_revision,
99
98
br_a.revision_history()[0])
100
99
br_a.push_stores(br_b)
101
100
# check that b now has all the data from a's first commit.
102
rev = br_b.get_revision(br_a.revision_history()[0])
103
tree = br_b.revision_tree(br_a.revision_history()[0])
101
rev = br_b.repository.get_revision(br_a.revision_history()[0])
102
tree = br_b.repository.revision_tree(br_a.revision_history()[0])
104
103
for file_id in tree:
105
104
if tree.inventory[file_id].kind == "file":
106
105
tree.get_file(file_id).read()
107
106
return br_a, br_b
109
def test_copy_branch(self):
108
def test_clone_branch(self):
110
109
"""Copy the stores from one branch to another"""
111
110
br_a, br_b = self.get_balanced_branch_pair()
112
111
commit(br_b, "silly commit")
114
br_c = copy_branch(br_a, 'c', basis_branch=br_b)
113
br_c = br_a.clone('c', basis_branch=br_b)
115
114
self.assertEqual(br_a.revision_history(), br_c.revision_history())
117
def test_copy_partial(self):
116
def test_clone_partial(self):
118
117
"""Copy only part of the history of a branch."""
119
118
self.build_tree(['a/', 'a/one'])
120
119
br_a = Branch.initialize('a')
123
122
self.build_tree(['a/two'])
124
123
br_a.working_tree().add(['two'])
125
124
br_a.working_tree().commit('commit two', rev_id='u@d-2')
126
br_b = copy_branch(br_a, 'b', revision='u@d-1')
125
br_b = br_a.clone('b', revision='u@d-1')
127
126
self.assertEqual(br_b.last_revision(), 'u@d-1')
128
127
self.assertTrue(os.path.exists('b/one'))
129
128
self.assertFalse(os.path.exists('b/two'))
133
132
branch = Branch.initialize(u'.')
134
133
branch.working_tree().add_pending_merge('non:existent@rev--ision--0--2')
135
134
branch.working_tree().commit('pretend to merge nonexistent-revision', rev_id='first')
136
rev = branch.get_revision(branch.last_revision())
135
rev = branch.repository.get_revision(branch.last_revision())
137
136
self.assertEqual(len(rev.parent_ids), 1)
138
137
# parent_sha1s is not populated now, WTF. rbc 20051003
139
138
self.assertEqual(len(rev.parent_sha1s), 0)
140
139
self.assertEqual(rev.parent_ids[0], 'non:existent@rev--ision--0--2')
142
141
def test_bad_revision(self):
143
branch = Branch.initialize(u'.')
144
self.assertRaises(errors.InvalidRevisionId, branch.get_revision, None)
142
branch = Branch.initialize('.')
143
self.assertRaises(errors.InvalidRevisionId,
144
branch.repository.get_revision, None)
146
146
# TODO 20051003 RBC:
147
147
# compare the gpg-to-sign info for a commit with a ghost and
162
162
['foo@azkhazan-123123-abcabc',
163
163
'wibble@fofof--20050401--1928390812'])
164
164
b.working_tree().commit("commit from base with two merges")
165
rev = b.get_revision(b.revision_history()[0])
165
rev = b.repository.get_revision(b.revision_history()[0])
166
166
self.assertEquals(len(rev.parent_ids), 2)
167
167
self.assertEquals(rev.parent_ids[0],
168
168
'foo@azkhazan-123123-abcabc')
175
175
branch = Branch.initialize(u'.')
176
176
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
177
177
from bzrlib.testament import Testament
178
branch.sign_revision('A', bzrlib.gpg.LoopbackGPGStrategy(None))
179
self.assertEqual(Testament.from_revision(branch, 'A').as_short_text(),
180
branch.revision_store.get('A', 'sig').read())
178
strategy = bzrlib.gpg.LoopbackGPGStrategy(None)
179
branch.repository.sign_revision('A', strategy)
180
self.assertEqual(Testament.from_revision(branch.repository,
181
'A').as_short_text(),
182
branch.repository.revision_store.get('A',
182
185
def test_store_signature(self):
183
branch = Branch.initialize(u'.')
184
branch.store_revision_signature(bzrlib.gpg.LoopbackGPGStrategy(None),
186
self.assertEqual('FOO', branch.revision_store.get('A', 'sig').read())
188
def test__relcontrolfilename(self):
189
branch = Branch.initialize(u'.')
190
self.assertEqual('.bzr/%25', branch._rel_controlfilename('%'))
192
def test__relcontrolfilename_empty(self):
193
branch = Branch.initialize(u'.')
194
self.assertEqual('.bzr', branch._rel_controlfilename(''))
186
branch = Branch.initialize('.')
187
branch.repository.store_revision_signature(
188
bzrlib.gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
189
self.assertEqual('FOO',
190
branch.repository.revision_store.get('A',
196
193
def test_nicks(self):
197
194
"""Branch nicknames"""
203
200
self.assertEqual(branch.nick, 'bzr.ab')
204
201
branch.nick = "Aaron's branch"
205
202
branch.nick = "Aaron's branch"
206
self.failUnless(os.path.exists(branch.controlfilename("branch.conf")))
203
self.failUnlessExists(branch.control_files.controlfilename("branch.conf"))
207
204
self.assertEqual(branch.nick, "Aaron's branch")
208
205
os.rename('bzr.ab', 'integration')
209
206
branch = Branch.open('integration')
217
214
branch = Branch.initialize('bzr.dev')
218
215
branch.nick = "My happy branch"
219
216
branch.working_tree().commit('My commit respect da nick.')
220
committed = branch.get_revision(branch.last_revision())
217
committed = branch.repository.get_revision(branch.last_revision())
221
218
self.assertEqual(committed.properties["branch-nick"],
222
219
"My happy branch")
329
326
super(TestBranchTransaction, self).setUp()
330
self.branch = Branch.initialize(u'.')
327
self.branch = Branch.initialize('.')
332
329
def test_default_get_transaction(self):
333
330
"""branch.get_transaction on a new branch should give a PassThrough."""
349
346
def test_finish_readonly_transaction_works(self):
350
347
self.branch._set_transaction(transactions.ReadOnlyTransaction())
351
348
self.branch._finish_transaction()
352
self.assertEqual(None, self.branch._transaction)
349
self.assertEqual(None, self.branch.control_files._transaction)
354
351
def test_unlock_calls_finish(self):
355
352
self.branch.lock_read()
356
353
transaction = InstrumentedTransaction()
357
self.branch._transaction = transaction
354
self.branch.control_files._transaction = transaction
358
355
self.branch.unlock()
359
356
self.assertEqual(['finish'], transaction.calls)
367
364
def test_lock_write_acquires_passthrough_transaction(self):
368
365
self.branch.lock_write()
369
366
# cannot use get_transaction as its magic
370
self.failUnless(isinstance(self.branch._transaction,
367
self.failUnless(isinstance(self.branch.control_files._transaction,
371
368
transactions.PassThroughTransaction))
372
369
self.branch.unlock()