39
39
branch = self.make_branch('.')
40
40
branch.repository.lock_write()
41
41
builder = branch.repository.get_commit_builder(
42
branch, [], branch.get_config())
42
branch, [], branch.get_config_stack())
43
43
self.assertIsInstance(builder, repository.CommitBuilder)
44
44
self.assertTrue(builder.random_revid)
45
45
branch.repository.commit_write_group()
148
148
rev = tree.branch.repository.get_revision(rev_id)
149
149
self.assertEqual('foo bar blah', rev.message)
151
def test_updates_branch(self):
152
tree = self.make_branch_and_tree(".")
155
builder = tree.branch.get_commit_builder([])
156
list(builder.record_iter_changes(tree, tree.last_revision(),
157
tree.iter_changes(tree.basis_tree())))
158
builder.finish_inventory()
159
will_update_branch = builder.updates_branch
160
rev_id = builder.commit('might update the branch')
163
actually_updated_branch = (tree.branch.last_revision() == rev_id)
164
self.assertEquals(actually_updated_branch, will_update_branch)
151
166
def test_commit_with_revision_id_record_entry_contents(self):
152
167
tree = self.make_branch_and_tree(".")
153
168
tree.lock_write()
247
264
if not builder.supports_record_entry_contents:
248
265
raise tests.TestNotApplicable("CommitBuilder doesn't support "
249
266
"record_entry_contents")
250
entry = tree.inventory['foo-id']
267
entry = tree.root_inventory['foo-id']
251
268
self.assertRaises(errors.RootMissing,
252
269
builder.record_entry_contents, entry, [], 'foo', tree,
253
270
tree.path_content_summary('foo'))
267
284
if not builder.supports_record_entry_contents:
268
285
raise tests.TestNotApplicable("CommitBuilder doesn't support "
269
286
"record_entry_contents")
287
builder.will_record_deletes()
270
288
ie = inventory.make_entry('directory', '', None,
271
289
tree.get_root_id())
272
290
delta, version_recorded, fs_hash = builder.record_entry_contents(
273
ie, [parent_tree.inventory], '', tree,
291
ie, [parent_tree.root_inventory], '', tree,
274
292
tree.path_content_summary(''))
275
293
# Regardless of repository root behaviour we should consider this a
276
294
# pointless commit.
282
300
if got_new_revision:
283
301
self.assertEqual(('', '', ie.file_id, ie), delta)
284
302
# The delta should be tracked
285
self.assertEqual(delta, builder._basis_delta[-1])
303
self.assertEqual(delta, builder.get_basis_delta()[-1])
287
305
self.assertEqual(None, delta)
288
306
# Directories do not get hashed.
306
324
# pointless commit.
307
325
self.assertFalse(builder.any_changes())
308
326
builder.finish_inventory()
309
328
builder_tree = builder.revision_tree()
310
329
new_root_id = builder_tree.get_root_id()
311
330
new_root_revision = builder_tree.get_file_revision(new_root_id)
357
375
if not builder.supports_record_entry_contents:
358
376
raise tests.TestNotApplicable("CommitBuilder doesn't "
359
377
"support record_entry_contents")
360
parent_invs = [basis.inventory]
378
parent_invs = [basis.root_inventory]
361
379
builder.will_record_deletes()
362
380
if builder.record_root_entry:
363
ie = basis.inventory.root.copy()
381
ie = basis.root_inventory.root.copy()
364
382
delta, _, _ = builder.record_entry_contents(ie, parent_invs,
365
383
'', tree, tree.path_content_summary(''))
366
384
if delta is not None:
417
435
"support record_entry_contents")
418
436
builder.will_record_deletes()
419
437
if builder.record_root_entry is True:
420
parent_invs = [basis.inventory]
421
del basis.inventory.root.children['foo']
422
builder.record_entry_contents(basis.inventory.root,
438
parent_invs = [basis.root_inventory]
439
del basis.root_inventory.root.children['foo']
440
builder.record_entry_contents(basis.root_inventory.root,
423
441
parent_invs, '', tree, tree.path_content_summary(''))
424
442
# the delta should be returned, and recorded in _basis_delta
425
443
delta = builder.record_delete("foo", "foo-id")
426
444
self.assertEqual(("foo", None, "foo-id", None), delta)
427
self.assertEqual(delta, builder._basis_delta[-1])
445
self.assertEqual(delta, builder.get_basis_delta()[-1])
428
446
builder.finish_inventory()
429
447
rev_id2 = builder.commit('delete foo')
447
465
builder = tree.branch.get_commit_builder([rev_id])
467
builder.will_record_deletes()
449
468
delete_change = ('foo-id', ('foo', None), True, (True, False),
450
469
(tree.path2id(''), None), ('foo', None), ('file', None),
452
471
list(builder.record_iter_changes(tree, rev_id,
453
472
[delete_change]))
454
473
self.assertEqual(("foo", None, "foo-id", None),
455
builder._basis_delta[0])
474
builder.get_basis_delta()[0])
456
475
self.assertTrue(builder.any_changes())
457
476
builder.finish_inventory()
458
477
rev_id2 = builder.commit('delete foo')
849
868
if not builder.supports_record_entry_contents:
850
869
raise tests.TestNotApplicable("CommitBuilder doesn't "
851
870
"support record_entry_contents")
871
builder.will_record_deletes()
852
872
parent_tree = tree.basis_tree()
853
873
parent_tree.lock_read()
854
874
self.addCleanup(parent_tree.unlock)
855
parent_invs = [parent_tree.inventory]
875
parent_invs = [parent_tree.root_inventory]
856
876
for parent_id in parent_ids[1:]:
857
877
parent_invs.append(tree.branch.repository.revision_tree(
858
parent_id).inventory)
878
parent_id).root_inventory)
860
880
builder.record_entry_contents(
861
881
inventory.make_entry('directory', '', None,
862
882
tree.get_root_id()), parent_invs, '', tree,
863
883
tree.path_content_summary(''))
864
884
def commit_id(file_id):
865
old_ie = tree.inventory[file_id]
885
old_ie = tree.root_inventory[file_id]
866
886
path = tree.id2path(file_id)
867
887
ie = inventory.make_entry(tree.kind(file_id), old_ie.name,
868
888
old_ie.parent_id, file_id)
874
894
tree, content_summary)
876
896
file_id = tree.path2id(new_name)
877
parent_id = tree.inventory[file_id].parent_id
897
parent_id = tree.root_inventory[file_id].parent_id
878
898
if parent_id != tree.get_root_id():
879
899
commit_id(parent_id)
880
900
# because a change of some sort is meant to have occurred,
896
916
if delta_against_basis:
897
917
expected_delta = (name, new_name, file_id, new_entry)
898
918
# The delta should be recorded
899
self.assertEqual(expected_delta, builder._basis_delta[-1])
919
self.assertEqual(expected_delta,
920
builder.get_basis_delta()[-1])
901
922
expected_delta = None
902
923
self.assertEqual(expected_delta, delta)
937
958
# record_entry_contents.
938
959
parent_ids = tree.get_parent_ids()
939
960
builder = tree.branch.get_commit_builder(parent_ids)
961
builder.will_record_deletes()
940
962
parent_tree = tree.basis_tree()
941
963
parent_tree.lock_read()
942
964
self.addCleanup(parent_tree.unlock)
958
980
self.assertEqualStat(result[2][1], tree_file_stat[1])
960
982
self.assertEqual([], result)
961
delta = builder._basis_delta
983
self.assertIs(None, builder.new_inventory)
984
builder.finish_inventory()
985
if tree.branch.repository._format.supports_full_versioned_files:
986
inv_key = (builder._new_revision_id,)
987
inv_sha1 = tree.branch.repository.inventories.get_sha1s(
989
self.assertEqual(inv_sha1, builder.inv_sha1)
990
self.assertIs(None, builder.new_inventory)
991
rev2 = builder.commit('')
992
delta = builder.get_basis_delta()
962
993
delta_dict = dict((change[2], change) for change in delta)
963
994
version_recorded = (file_id in delta_dict and
964
995
delta_dict[file_id][3] is not None and
965
delta_dict[file_id][3].revision == builder._new_revision_id)
996
delta_dict[file_id][3].revision == rev2)
966
997
if records_version:
967
998
self.assertTrue(version_recorded)
969
1000
self.assertFalse(version_recorded)
970
self.assertIs(None, builder.new_inventory)
971
builder.finish_inventory()
972
if tree.branch.repository._format.supports_full_versioned_files:
973
inv_key = (builder._new_revision_id,)
974
inv_sha1 = tree.branch.repository.inventories.get_sha1s(
976
self.assertEqual(inv_sha1, builder.inv_sha1)
977
self.assertIs(None, builder.new_inventory)
978
new_inventory = builder.revision_tree().inventory
1002
new_inventory = builder.revision_tree().root_inventory
979
1003
new_entry = new_inventory[file_id]
980
1004
if delta_against_basis:
981
1005
expected_delta = (name, new_name, file_id, new_entry)
1289
1315
expect_fs_hash=True)
1291
1317
def test_last_modified_dir_file_ric(self):
1292
self._check_kind_change(self.make_dir, self.make_file,
1293
expect_fs_hash=True,
1294
mini_commit=self.mini_commit_record_iter_changes)
1319
self._check_kind_change(self.make_dir, self.make_file,
1320
expect_fs_hash=True,
1321
mini_commit=self.mini_commit_record_iter_changes)
1322
except errors.UnsupportedKindChange:
1323
raise tests.TestSkipped(
1324
"tree does not support changing entry kind from "
1325
"directory to file")
1296
1327
def test_last_modified_dir_link(self):
1297
1328
self._check_kind_change(self.make_dir, self.make_link)
1299
1330
def test_last_modified_dir_link_ric(self):
1300
self._check_kind_change(self.make_dir, self.make_link,
1301
mini_commit=self.mini_commit_record_iter_changes)
1332
self._check_kind_change(self.make_dir, self.make_link,
1333
mini_commit=self.mini_commit_record_iter_changes)
1334
except errors.UnsupportedKindChange:
1335
raise tests.TestSkipped(
1336
"tree does not support changing entry kind from "
1337
"directory to link")
1303
1339
def test_last_modified_link_file(self):
1304
1340
self._check_kind_change(self.make_link, self.make_file,
1335
1371
branch.repository.lock_write()
1336
1372
self.addCleanup(branch.repository.unlock)
1337
1373
self.assertRaises(ValueError, branch.repository.get_commit_builder,
1338
branch, [], branch.get_config(),
1374
branch, [], branch.get_config_stack(),
1339
1375
revprops={'invalid': u'property\rwith\r\ninvalid chars'})
1341
1377
def test_commit_builder_commit_with_invalid_message(self):
1343
1379
branch.repository.lock_write()
1344
1380
self.addCleanup(branch.repository.unlock)
1345
1381
builder = branch.repository.get_commit_builder(branch, [],
1346
branch.get_config())
1382
branch.get_config_stack())
1347
1383
self.addCleanup(branch.repository.abort_write_group)
1348
1384
self.assertRaises(ValueError, builder.commit,
1349
1385
u'Invalid\r\ncommit message\r\n')
1355
1391
self.addCleanup(branch.repository.unlock)
1356
1392
self.assertRaises(UnicodeDecodeError,
1357
1393
branch.repository.get_commit_builder,
1358
branch, [], branch.get_config(),
1394
branch, [], branch.get_config_stack(),
1359
1395
committer="Erik B\xe5gfors <erik@example.com>")
1361
1397
def test_stacked_repositories_reject_commit_builder(self):
1372
1408
self.addCleanup(repo_local.lock_write().unlock)
1373
1409
if not repo_local._format.supports_chks:
1374
1410
self.assertRaises(errors.BzrError, repo_local.get_commit_builder,
1375
branch, [], branch.get_config())
1411
branch, [], branch.get_config_stack())
1377
1413
builder = repo_local.get_commit_builder(branch, [],
1378
branch.get_config())
1414
branch.get_config_stack())
1379
1415
builder.abort()
1381
1417
def test_committer_no_username(self):