107
102
tree1.lock_read()
108
103
text = tree1.get_file_text('hello')
110
self.assertEqual(b'hello world', text)
105
self.assertEqual('hello world', text)
112
107
tree2 = b.repository.revision_tree(rev2)
113
108
tree2.lock_read()
114
109
text = tree2.get_file_text('hello')
116
self.assertEqual(b'version 2', text)
111
self.assertEqual('version 2', text)
118
113
def test_commit_lossy_native(self):
119
114
"""Attempt a lossy commit to a native branch."""
120
115
wt = self.make_branch_and_tree('.')
122
with open('hello', 'w') as f:
123
f.write('hello world')
117
with open('hello', 'w') as f: f.write('hello world')
125
119
revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
126
self.assertEqual(b'revid', revid)
120
self.assertEqual('revid', revid)
128
122
def test_commit_lossy_foreign(self):
129
123
"""Attempt a lossy commit to a foreign branch."""
130
124
test_foreign.register_dummy_foreign_for_test(self)
131
125
wt = self.make_branch_and_tree('.',
132
format=test_foreign.DummyForeignVcsDirFormat())
126
format=test_foreign.DummyForeignVcsDirFormat())
134
with open('hello', 'w') as f:
135
f.write('hello world')
128
with open('hello', 'w') as f: f.write('hello world')
137
130
revid = wt.commit(message='add hello', lossy=True,
138
timestamp=1302659388, timezone=0)
139
self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
131
timestamp=1302659388, timezone=0)
132
self.assertEqual('dummy-v1:1302659388.0-0-UNKNOWN', revid)
141
134
def test_commit_bound_lossy_foreign(self):
142
135
"""Attempt a lossy commit to a bzr branch bound to a foreign branch."""
143
136
test_foreign.register_dummy_foreign_for_test(self)
144
137
foreign_branch = self.make_branch('foreign',
145
format=test_foreign.DummyForeignVcsDirFormat())
138
format=test_foreign.DummyForeignVcsDirFormat())
146
139
wt = foreign_branch.create_checkout("local")
148
with open('local/hello', 'w') as f:
149
f.write('hello world')
141
with open('local/hello', 'w') as f: f.write('hello world')
151
143
revid = wt.commit(message='add hello', lossy=True,
152
timestamp=1302659388, timezone=0)
153
self.assertEqual(b'dummy-v1:1302659388-0-0', revid)
154
self.assertEqual(b'dummy-v1:1302659388-0-0',
155
foreign_branch.last_revision())
156
self.assertEqual(b'dummy-v1:1302659388-0-0',
157
wt.branch.last_revision())
144
timestamp=1302659388, timezone=0)
145
self.assertEqual('dummy-v1:1302659388.0-0-0', revid)
146
self.assertEqual('dummy-v1:1302659388.0-0-0',
147
foreign_branch.last_revision())
148
self.assertEqual('dummy-v1:1302659388.0-0-0',
149
wt.branch.last_revision())
159
151
def test_missing_commit(self):
160
152
"""Test a commit with a missing file"""
161
153
wt = self.make_branch_and_tree('.')
163
with open('hello', 'w') as f:
164
f.write('hello world')
155
with open('hello', 'w') as f: f.write('hello world')
165
156
wt.add(['hello'], [b'hello-id'])
166
157
wt.commit(message='add hello')
226
216
"""Selective commit in tree with deletions"""
227
217
wt = self.make_branch_and_tree('.')
229
with open('hello', 'w') as f:
231
with open('buongia', 'w') as f:
219
with open('hello', 'w') as f: f.write('hello')
220
with open('buongia', 'w') as f: f.write('buongia')
233
221
wt.add(['hello', 'buongia'],
234
[b'hello-id', b'buongia-id'])
222
['hello-id', 'buongia-id'])
235
223
wt.commit(message='add files',
236
rev_id=b'test@rev-1')
224
rev_id=b'test@rev-1')
238
226
os.remove('hello')
239
with open('buongia', 'w') as f:
227
with open('buongia', 'w') as f: f.write('new text')
241
228
wt.commit(message='update text',
242
specific_files=['buongia'],
243
allow_pointless=False,
244
rev_id=b'test@rev-2')
229
specific_files=['buongia'],
230
allow_pointless=False,
231
rev_id=b'test@rev-2')
246
233
wt.commit(message='remove hello',
247
specific_files=['hello'],
248
allow_pointless=False,
249
rev_id=b'test@rev-3')
234
specific_files=['hello'],
235
allow_pointless=False,
236
rev_id=b'test@rev-3')
251
238
eq = self.assertEqual
254
tree2 = b.repository.revision_tree(b'test@rev-2')
241
tree2 = b.repository.revision_tree('test@rev-2')
255
242
tree2.lock_read()
256
243
self.addCleanup(tree2.unlock)
257
244
self.assertTrue(tree2.has_filename('hello'))
258
self.assertEqual(tree2.get_file_text('hello'), b'hello')
259
self.assertEqual(tree2.get_file_text('buongia'), b'new text')
245
self.assertEqual(tree2.get_file_text('hello'), 'hello')
246
self.assertEqual(tree2.get_file_text('buongia'), 'new text')
261
tree3 = b.repository.revision_tree(b'test@rev-3')
248
tree3 = b.repository.revision_tree('test@rev-3')
262
249
tree3.lock_read()
263
250
self.addCleanup(tree3.unlock)
264
251
self.assertFalse(tree3.has_filename('hello'))
265
self.assertEqual(tree3.get_file_text('buongia'), b'new text')
252
self.assertEqual(tree3.get_file_text('buongia'), 'new text')
267
254
def test_commit_rename(self):
268
255
"""Test commit of a revision where a file is renamed."""
273
260
tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
275
262
tree.rename_one('hello', 'fruity')
276
tree.commit(message='renamed', rev_id=b'test@rev-2',
277
allow_pointless=False)
263
tree.commit(message='renamed', rev_id=b'test@rev-2', allow_pointless=False)
279
265
eq = self.assertEqual
280
266
tree1 = b.repository.revision_tree(b'test@rev-1')
281
267
tree1.lock_read()
282
268
self.addCleanup(tree1.unlock)
283
269
eq(tree1.id2path(b'hello-id'), 'hello')
284
eq(tree1.get_file_text('hello'), b'contents of hello\n')
270
eq(tree1.get_file_text('hello'), 'contents of hello\n')
285
271
self.assertFalse(tree1.has_filename('fruity'))
286
272
self.check_tree_shape(tree1, ['hello'])
287
273
eq(tree1.get_file_revision('hello'), b'test@rev-1')
371
356
for i in range(4):
372
with open('hello', 'w') as f:
373
f.write((str(i) * 4) + '\n')
357
with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
375
359
wt.add(['hello'], [b'hello-id'])
376
rev_id = b'test@rev-%d' % (i + 1)
360
rev_id = 'test@rev-%d' % (i+1)
377
361
rev_ids.append(rev_id)
378
wt.commit(message='rev %d' % (i + 1),
362
wt.commit(message='rev %d' % (i+1),
380
364
for i in range(4):
381
self.assertThat(rev_ids[:i + 1],
382
MatchesAncestry(b.repository, rev_ids[i]))
365
self.assertThat(rev_ids[:i+1],
366
MatchesAncestry(b.repository, rev_ids[i]))
384
368
def test_commit_new_subdir_child_selective(self):
385
369
wt = self.make_branch_and_tree('.')
387
371
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
388
372
wt.add(['dir', 'dir/file1', 'dir/file2'],
389
[b'dirid', b'file1id', b'file2id'])
373
['dirid', 'file1id', 'file2id'])
390
374
wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
391
inv = b.repository.get_inventory(b'1')
392
self.assertEqual(b'1', inv.get_entry(b'dirid').revision)
393
self.assertEqual(b'1', inv.get_entry(b'file1id').revision)
375
inv = b.repository.get_inventory('1')
376
self.assertEqual('1', inv.get_entry('dirid').revision)
377
self.assertEqual('1', inv.get_entry('file1id').revision)
394
378
# FIXME: This should raise a KeyError I think, rbc20051006
395
self.assertRaises(BzrError, inv.get_entry, b'file2id')
379
self.assertRaises(BzrError, inv.get_entry, 'file2id')
397
381
def test_strict_commit(self):
398
382
"""Try and commit with unknown files and strict = True, should fail."""
399
383
from ..errors import StrictCommitFailed
400
384
wt = self.make_branch_and_tree('.')
402
with open('hello', 'w') as f:
403
f.write('hello world')
386
with open('hello', 'w') as f: f.write('hello world')
405
with open('goodbye', 'w') as f:
406
f.write('goodbye cruel world!')
388
with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
407
389
self.assertRaises(StrictCommitFailed, wt.commit,
408
message='add hello but not goodbye', strict=True)
390
message='add hello but not goodbye', strict=True)
410
392
def test_strict_commit_without_unknowns(self):
411
393
"""Try and commit with no unknown files and strict = True,
413
395
wt = self.make_branch_and_tree('.')
415
with open('hello', 'w') as f:
416
f.write('hello world')
397
with open('hello', 'w') as f: f.write('hello world')
418
399
wt.commit(message='add hello', strict=True)
445
423
wt = self.make_branch_and_tree('.')
446
424
branch = wt.branch
447
425
wt.commit("base", allow_pointless=True, rev_id=b'A')
448
self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
426
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
450
from ..bzr.testament import Testament
428
from ..testament import Testament
451
429
# monkey patch gpg signing mechanism
452
430
breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
453
conf = config.MemoryStack(b'''
431
conf = config.MemoryStack('''
454
432
create_signatures=always
456
434
commit.Commit(config_stack=conf).commit(
457
435
message="base", allow_pointless=True, rev_id=b'B',
461
438
return breezy.gpg.LoopbackGPGStrategy(None).sign(
462
text, breezy.gpg.MODE_CLEAR)
439
text, breezy.gpg.MODE_CLEAR)
463
440
self.assertEqual(sign(Testament.from_revision(branch.repository,
464
b'B').as_short_text()),
465
branch.repository.get_signature_text(b'B'))
441
'B').as_short_text()),
442
branch.repository.get_signature_text('B'))
467
444
breezy.gpg.GPGStrategy = oldstrategy
553
528
# do a commit to the other branch changing the content file so
554
529
# that our commit after merging will have a merged revision in the
555
530
# content file history.
556
self.build_tree_contents(
557
[('other/content_file', b'change in other\n')])
531
self.build_tree_contents([('other/content_file', b'change in other\n')])
558
532
other_tree.commit('change in other')
560
534
# do a merge into the bound branch from other, and then change the
561
535
# content file locally to force a new revision (rather than using the
562
536
# revision from other). This forces extra processing in commit.
563
537
bound_tree.merge_from_branch(other_tree.branch)
564
self.build_tree_contents(
565
[('bound/content_file', b'change in bound\n')])
538
self.build_tree_contents([('bound/content_file', b'change in bound\n')])
567
540
# before #34959 was fixed, this failed with 'revision not present in
568
541
# weave' when trying to implicitly push from the bound branch to the master
682
def test_unsupported_symlink_commit(self):
683
self.requireFeature(SymlinkFeature)
684
tree = self.make_branch_and_tree('.')
685
self.build_tree(['hello'])
687
tree.commit('added hello', rev_id=b'hello_id')
688
os.symlink('hello', 'foo')
690
tree.commit('added foo', rev_id=b'foo_id')
692
trace.push_log_file(log)
693
os_symlink = getattr(os, 'symlink', None)
696
# At this point as bzr thinks symlinks are not supported
697
# we should get a warning about symlink foo and bzr should
698
# not think its removed.
700
self.build_tree(['world'])
702
tree.commit('added world', rev_id=b'world_id')
705
os.symlink = os_symlink
706
self.assertContainsRe(
708
b'Ignoring "foo" as symlinks are not '
709
b'supported on this filesystem\\.')
711
654
def test_commit_kind_changes(self):
712
655
self.requireFeature(SymlinkFeature)
713
656
tree = self.make_branch_and_tree('.')
816
758
tree = self.make_branch_and_tree('foo')
817
759
# pending merge would turn into a left parent
818
760
tree.commit('commit 1')
819
tree.add_parent_tree_id(b'example')
761
tree.add_parent_tree_id('example')
820
762
self.build_tree(['foo/bar', 'foo/baz'])
821
763
tree.add(['bar', 'baz'])
822
764
err = self.assertRaises(CannotCommitSelectedFileMerge,
823
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
765
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
824
766
self.assertEqual(['bar', 'baz'], err.files)
825
767
self.assertEqual('Selected-file commit of merges is not supported'
826
768
' yet: files bar, baz', str(err))
870
812
def test_multiple_authors(self):
871
813
tree = self.make_branch_and_tree('foo')
872
814
rev_id = tree.commit('commit 1',
873
authors=['John Doe <jdoe@example.com>',
874
'Jane Rey <jrey@example.com>'])
815
authors=['John Doe <jdoe@example.com>',
816
'Jane Rey <jrey@example.com>'])
875
817
rev = tree.branch.repository.get_revision(rev_id)
876
818
self.assertEqual('John Doe <jdoe@example.com>\n'
877
'Jane Rey <jrey@example.com>', rev.properties['authors'])
819
'Jane Rey <jrey@example.com>', rev.properties['authors'])
878
820
self.assertFalse('author' in rev.properties)
880
822
def test_author_with_newline_rejected(self):
881
823
tree = self.make_branch_and_tree('foo')
882
824
self.assertRaises(AssertionError, tree.commit, 'commit 1',
883
authors=['John\nDoe <jdoe@example.com>'])
825
authors=['John\nDoe <jdoe@example.com>'])
885
827
def test_commit_with_checkout_and_branch_sharing_repo(self):
886
828
repo = self.make_repository('repo', shared=True)
888
830
branch = controldir.ControlDir.create_branch_convenience('repo/branch')
889
831
tree2 = branch.create_checkout('repo/tree2')
890
832
tree2.commit('message', rev_id=b'rev1')
891
self.assertTrue(tree2.branch.repository.has_revision(b'rev1'))
833
self.assertTrue(tree2.branch.repository.has_revision('rev1'))
894
836
class FilterExcludedTests(TestCase):
896
838
def test_add_file_not_excluded(self):
899
'fid', (None, 'newpath'),
900
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
901
('file', 'file'), (True, True))]
902
self.assertEqual(changes, list(
903
filter_excluded(changes, ['otherpath'])))
840
('fid', (None, 'newpath'),
841
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
842
('file', 'file'), (True, True))]
843
self.assertEqual(changes, list(filter_excluded(changes, ['otherpath'])))
905
845
def test_add_file_excluded(self):
908
'fid', (None, 'newpath'),
909
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
910
('file', 'file'), (True, True))]
847
('fid', (None, 'newpath'),
848
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
849
('file', 'file'), (True, True))]
911
850
self.assertEqual([], list(filter_excluded(changes, ['newpath'])))
913
852
def test_delete_file_excluded(self):
916
'fid', ('somepath', None),
917
0, (False, None), ('pid', None), ('newpath', None),
918
('file', None), (True, None))]
854
('fid', ('somepath', None),
855
0, (False, None), ('pid', None), ('newpath', None),
856
('file', None), (True, None))]
919
857
self.assertEqual([], list(filter_excluded(changes, ['somepath'])))
921
859
def test_move_from_or_to_excluded(self):
924
'fid', ('oldpath', 'newpath'),
925
0, (False, False), ('pid', 'pid'), ('oldpath', 'newpath'),
926
('file', 'file'), (True, True))]
861
('fid', ('oldpath', 'newpath'),
862
0, (False, False), ('pid', 'pid'), ('oldpath', 'newpath'),
863
('file', 'file'), (True, True))]
927
864
self.assertEqual([], list(filter_excluded(changes, ['oldpath'])))
928
865
self.assertEqual([], list(filter_excluded(changes, ['newpath'])))