392
413
self.assertRaises(LockContention, wt.commit, 'silly')
394
415
master_branch.unlock()
417
def test_commit_bound_merge(self):
418
# see bug #43959; commit of a merge in a bound branch fails to push
419
# the new commit into the master
420
master_branch = self.make_branch('master')
421
bound_tree = self.make_branch_and_tree('bound')
422
bound_tree.branch.bind(master_branch)
424
self.build_tree_contents([('bound/content_file', 'initial contents\n')])
425
bound_tree.add(['content_file'])
426
bound_tree.commit(message='woo!')
428
other_bzrdir = master_branch.bzrdir.sprout('other')
429
other_tree = other_bzrdir.open_workingtree()
431
# do a commit to the the other branch changing the content file so
432
# that our commit after merging will have a merged revision in the
433
# content file history.
434
self.build_tree_contents([('other/content_file', 'change in other\n')])
435
other_tree.commit('change in other')
437
# do a merge into the bound branch from other, and then change the
438
# content file locally to force a new revision (rather than using the
439
# revision from other). This forces extra processing in commit.
440
bound_tree.merge_from_branch(other_tree.branch)
441
self.build_tree_contents([('bound/content_file', 'change in bound\n')])
443
# before #34959 was fixed, this failed with 'revision not present in
444
# weave' when trying to implicitly push from the bound branch to the master
445
bound_tree.commit(message='commit of merge in bound tree')
447
def test_commit_reporting_after_merge(self):
448
# when doing a commit of a merge, the reporter needs to still
449
# be called for each item that is added/removed/deleted.
450
this_tree = self.make_branch_and_tree('this')
451
# we need a bunch of files and dirs, to perform one action on each.
454
'this/dirtoreparent/',
457
'this/filetoreparent',
474
this_tree.commit('create_files')
475
other_dir = this_tree.bzrdir.sprout('other')
476
other_tree = other_dir.open_workingtree()
477
other_tree.lock_write()
478
# perform the needed actions on the files and dirs.
480
other_tree.rename_one('dirtorename', 'renameddir')
481
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
482
other_tree.rename_one('filetorename', 'renamedfile')
483
other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
484
other_tree.remove(['dirtoremove', 'filetoremove'])
485
self.build_tree_contents([
487
('other/filetomodify', 'new content'),
488
('other/newfile', 'new file content')])
489
other_tree.add('newfile')
490
other_tree.add('newdir/')
491
other_tree.commit('modify all sample files and dirs.')
494
this_tree.merge_from_branch(other_tree.branch)
495
reporter = CapturingReporter()
496
this_tree.commit('do the commit', reporter=reporter)
498
('change', 'unchanged', ''),
499
('change', 'unchanged', 'dirtoleave'),
500
('change', 'unchanged', 'filetoleave'),
501
('change', 'modified', 'filetomodify'),
502
('change', 'added', 'newdir'),
503
('change', 'added', 'newfile'),
504
('renamed', 'renamed', 'dirtorename', 'renameddir'),
505
('renamed', 'renamed', 'dirtoreparent', 'renameddir/reparenteddir'),
506
('renamed', 'renamed', 'filetoreparent', 'renameddir/reparentedfile'),
507
('renamed', 'renamed', 'filetorename', 'renamedfile'),
508
('deleted', 'dirtoremove'),
509
('deleted', 'filetoremove'),
513
def test_commit_removals_respects_filespec(self):
514
"""Commit respects the specified_files for removals."""
515
tree = self.make_branch_and_tree('.')
516
self.build_tree(['a', 'b'])
518
tree.commit('added a, b')
519
tree.remove(['a', 'b'])
520
tree.commit('removed a', specific_files='a')
521
basis = tree.basis_tree().inventory
522
self.assertIs(None, basis.path2id('a'))
523
self.assertFalse(basis.path2id('b') is None)
525
def test_commit_saves_1ms_timestamp(self):
526
"""Passing in a timestamp is saved with 1ms resolution"""
527
tree = self.make_branch_and_tree('.')
528
self.build_tree(['a'])
530
tree.commit('added a', timestamp=1153248633.4186721, timezone=0,
533
rev = tree.branch.repository.get_revision('a1')
534
self.assertEqual(1153248633.419, rev.timestamp)
536
def test_commit_has_1ms_resolution(self):
537
"""Allowing commit to generate the timestamp also has 1ms resolution"""
538
tree = self.make_branch_and_tree('.')
539
self.build_tree(['a'])
541
tree.commit('added a', rev_id='a1')
543
rev = tree.branch.repository.get_revision('a1')
544
timestamp = rev.timestamp
545
timestamp_1ms = round(timestamp, 3)
546
self.assertEqual(timestamp_1ms, timestamp)
548
def test_commit_unversioned_specified(self):
549
"""Commit should raise if specified files isn't in basis or worktree"""
550
tree = self.make_branch_and_tree('.')
551
self.assertRaises(errors.PathsNotVersionedError, tree.commit,
552
'message', specific_files=['bogus'])