106
98
tree1 = b.repository.revision_tree(rev1)
108
text = tree1.get_file_text('hello')
100
text = tree1.get_file_text(file_id)
110
self.assertEqual(b'hello world', text)
102
self.assertEqual('hello world', text)
112
104
tree2 = b.repository.revision_tree(rev2)
113
105
tree2.lock_read()
114
text = tree2.get_file_text('hello')
106
text = tree2.get_file_text(file_id)
116
self.assertEqual(b'version 2', text)
108
self.assertEqual('version 2', text)
118
110
def test_commit_lossy_native(self):
119
111
"""Attempt a lossy commit to a native branch."""
120
112
wt = self.make_branch_and_tree('.')
122
with open('hello', 'w') as f:
123
f.write('hello world')
114
with file('hello', 'w') as f: f.write('hello world')
125
revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
126
self.assertEqual(b'revid', revid)
116
revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
117
self.assertEqual('revid', revid)
128
119
def test_commit_lossy_foreign(self):
129
120
"""Attempt a lossy commit to a foreign branch."""
130
121
test_foreign.register_dummy_foreign_for_test(self)
131
122
wt = self.make_branch_and_tree('.',
132
format=test_foreign.DummyForeignVcsDirFormat())
123
format=test_foreign.DummyForeignVcsDirFormat())
134
with open('hello', 'w') as f:
135
f.write('hello world')
125
with file('hello', 'w') as f: f.write('hello world')
137
127
revid = wt.commit(message='add hello', lossy=True,
138
timestamp=1302659388, timezone=0)
139
self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
128
timestamp=1302659388, timezone=0)
129
self.assertEqual('dummy-v1:1302659388.0-0-UNKNOWN', revid)
141
131
def test_commit_bound_lossy_foreign(self):
142
132
"""Attempt a lossy commit to a bzr branch bound to a foreign branch."""
143
133
test_foreign.register_dummy_foreign_for_test(self)
144
134
foreign_branch = self.make_branch('foreign',
145
format=test_foreign.DummyForeignVcsDirFormat())
135
format=test_foreign.DummyForeignVcsDirFormat())
146
136
wt = foreign_branch.create_checkout("local")
148
with open('local/hello', 'w') as f:
149
f.write('hello world')
138
with file('local/hello', 'w') as f: f.write('hello world')
151
140
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())
141
timestamp=1302659388, timezone=0)
142
self.assertEqual('dummy-v1:1302659388.0-0-0', revid)
143
self.assertEqual('dummy-v1:1302659388.0-0-0',
144
foreign_branch.last_revision())
145
self.assertEqual('dummy-v1:1302659388.0-0-0',
146
wt.branch.last_revision())
159
148
def test_missing_commit(self):
160
149
"""Test a commit with a missing file"""
161
150
wt = self.make_branch_and_tree('.')
163
with open('hello', 'w') as f:
164
f.write('hello world')
165
wt.add(['hello'], [b'hello-id'])
152
with file('hello', 'w') as f: f.write('hello world')
153
wt.add(['hello'], ['hello-id'])
166
154
wt.commit(message='add hello')
168
156
os.remove('hello')
169
157
reporter = CapturingReporter()
170
wt.commit('removed hello', rev_id=b'rev2', reporter=reporter)
158
wt.commit('removed hello', rev_id='rev2', reporter=reporter)
171
159
self.assertEqual(
172
160
[('missing', u'hello'), ('deleted', u'hello')],
175
tree = b.repository.revision_tree(b'rev2')
176
self.assertFalse(tree.has_filename('hello'))
163
tree = b.repository.revision_tree('rev2')
164
self.assertFalse(tree.has_id('hello-id'))
178
166
def test_partial_commit_move(self):
179
167
"""Test a partial commit where a file was renamed but not committed.
189
177
self.build_tree(['annotate/', 'annotate/foo.py',
190
178
'olive/', 'olive/dialog.py'
192
180
wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
193
181
wt.commit(message='add files')
194
182
wt.rename_one("olive/dialog.py", "aaa")
195
self.build_tree_contents([('annotate/foo.py', b'modified\n')])
183
self.build_tree_contents([('annotate/foo.py', 'modified\n')])
196
184
wt.commit('renamed hello', specific_files=["annotate"])
198
186
def test_pointless_commit(self):
199
187
"""Commit refuses unless there are changes or it's forced."""
200
188
wt = self.make_branch_and_tree('.')
202
with open('hello', 'w') as f:
190
with file('hello', 'w') as f: f.write('hello')
204
191
wt.add(['hello'])
205
192
wt.commit(message='add hello')
206
193
self.assertEqual(b.revno(), 1)
226
213
"""Selective commit in tree with deletions"""
227
214
wt = self.make_branch_and_tree('.')
229
with open('hello', 'w') as f:
231
with open('buongia', 'w') as f:
216
with file('hello', 'w') as f: f.write('hello')
217
with file('buongia', 'w') as f: f.write('buongia')
233
218
wt.add(['hello', 'buongia'],
234
[b'hello-id', b'buongia-id'])
219
['hello-id', 'buongia-id'])
235
220
wt.commit(message='add files',
236
rev_id=b'test@rev-1')
238
223
os.remove('hello')
239
with open('buongia', 'w') as f:
224
with file('buongia', 'w') as f: f.write('new text')
241
225
wt.commit(message='update text',
242
specific_files=['buongia'],
243
allow_pointless=False,
244
rev_id=b'test@rev-2')
226
specific_files=['buongia'],
227
allow_pointless=False,
246
230
wt.commit(message='remove hello',
247
specific_files=['hello'],
248
allow_pointless=False,
249
rev_id=b'test@rev-3')
231
specific_files=['hello'],
232
allow_pointless=False,
251
235
eq = self.assertEqual
254
tree2 = b.repository.revision_tree(b'test@rev-2')
238
tree2 = b.repository.revision_tree('test@rev-2')
255
239
tree2.lock_read()
256
240
self.addCleanup(tree2.unlock)
257
241
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')
242
self.assertEqual(tree2.get_file_text('hello-id'), 'hello')
243
self.assertEqual(tree2.get_file_text('buongia-id'), 'new text')
261
tree3 = b.repository.revision_tree(b'test@rev-3')
245
tree3 = b.repository.revision_tree('test@rev-3')
262
246
tree3.lock_read()
263
247
self.addCleanup(tree3.unlock)
264
248
self.assertFalse(tree3.has_filename('hello'))
265
self.assertEqual(tree3.get_file_text('buongia'), b'new text')
249
self.assertEqual(tree3.get_file_text('buongia-id'), 'new text')
267
251
def test_commit_rename(self):
268
252
"""Test commit of a revision where a file is renamed."""
269
253
tree = self.make_branch_and_tree('.')
271
255
self.build_tree(['hello'], line_endings='binary')
272
tree.add(['hello'], [b'hello-id'])
273
tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
256
tree.add(['hello'], ['hello-id'])
257
tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
275
259
tree.rename_one('hello', 'fruity')
276
tree.commit(message='renamed', rev_id=b'test@rev-2',
277
allow_pointless=False)
260
tree.commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
279
262
eq = self.assertEqual
280
tree1 = b.repository.revision_tree(b'test@rev-1')
263
tree1 = b.repository.revision_tree('test@rev-1')
281
264
tree1.lock_read()
282
265
self.addCleanup(tree1.unlock)
283
eq(tree1.id2path(b'hello-id'), 'hello')
284
eq(tree1.get_file_text('hello'), b'contents of hello\n')
266
eq(tree1.id2path('hello-id'), 'hello')
267
eq(tree1.get_file_text('hello-id'), 'contents of hello\n')
285
268
self.assertFalse(tree1.has_filename('fruity'))
286
269
self.check_tree_shape(tree1, ['hello'])
287
eq(tree1.get_file_revision('hello'), b'test@rev-1')
270
eq(tree1.get_file_revision('hello-id'), 'test@rev-1')
289
tree2 = b.repository.revision_tree(b'test@rev-2')
272
tree2 = b.repository.revision_tree('test@rev-2')
290
273
tree2.lock_read()
291
274
self.addCleanup(tree2.unlock)
292
eq(tree2.id2path(b'hello-id'), 'fruity')
293
eq(tree2.get_file_text('fruity'), b'contents of hello\n')
275
eq(tree2.id2path('hello-id'), 'fruity')
276
eq(tree2.get_file_text('hello-id'), 'contents of hello\n')
294
277
self.check_tree_shape(tree2, ['fruity'])
295
eq(tree2.get_file_revision('fruity'), b'test@rev-2')
278
eq(tree2.get_file_revision('hello-id'), 'test@rev-2')
297
280
def test_reused_rev_id(self):
298
281
"""Test that a revision id cannot be reused in a branch"""
299
282
wt = self.make_branch_and_tree('.')
301
wt.commit('initial', rev_id=b'test@rev-1', allow_pointless=True)
284
wt.commit('initial', rev_id='test@rev-1', allow_pointless=True)
302
285
self.assertRaises(Exception,
304
287
message='reused id',
305
rev_id=b'test@rev-1',
306
289
allow_pointless=True)
308
291
def test_commit_move(self):
347
330
inv = b.repository.get_inventory(r4)
348
eq(inv.get_entry(b'hello-id').revision, r4)
349
eq(inv.get_entry(b'a-id').revision, r1)
350
eq(inv.get_entry(b'b-id').revision, r3)
331
eq(inv['hello-id'].revision, r4)
332
eq(inv['a-id'].revision, r1)
333
eq(inv['b-id'].revision, r3)
352
335
def test_removed_commit(self):
353
336
"""Commit with a removed file"""
354
337
wt = self.make_branch_and_tree('.')
356
with open('hello', 'w') as f:
357
f.write('hello world')
358
wt.add(['hello'], [b'hello-id'])
339
with file('hello', 'w') as f: f.write('hello world')
340
wt.add(['hello'], ['hello-id'])
359
341
wt.commit(message='add hello')
360
342
wt.remove('hello')
361
wt.commit('removed hello', rev_id=b'rev2')
343
wt.commit('removed hello', rev_id='rev2')
363
tree = b.repository.revision_tree(b'rev2')
364
self.assertFalse(tree.has_filename('hello'))
345
tree = b.repository.revision_tree('rev2')
346
self.assertFalse(tree.has_id('hello-id'))
366
348
def test_committed_ancestry(self):
367
349
"""Test commit appends revisions to ancestry."""
371
353
for i in range(4):
372
with open('hello', 'w') as f:
373
f.write((str(i) * 4) + '\n')
354
with file('hello', 'w') as f: f.write((str(i) * 4) + '\n')
375
wt.add(['hello'], [b'hello-id'])
376
rev_id = b'test@rev-%d' % (i + 1)
356
wt.add(['hello'], ['hello-id'])
357
rev_id = 'test@rev-%d' % (i+1)
377
358
rev_ids.append(rev_id)
378
wt.commit(message='rev %d' % (i + 1),
359
wt.commit(message='rev %d' % (i+1),
380
361
for i in range(4):
381
self.assertThat(rev_ids[:i + 1],
382
MatchesAncestry(b.repository, rev_ids[i]))
362
self.assertThat(rev_ids[:i+1],
363
MatchesAncestry(b.repository, rev_ids[i]))
384
365
def test_commit_new_subdir_child_selective(self):
385
366
wt = self.make_branch_and_tree('.')
387
368
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
388
369
wt.add(['dir', 'dir/file1', 'dir/file2'],
389
[b'dirid', b'file1id', b'file2id'])
390
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)
370
['dirid', 'file1id', 'file2id'])
371
wt.commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
372
inv = b.repository.get_inventory('1')
373
self.assertEqual('1', inv['dirid'].revision)
374
self.assertEqual('1', inv['file1id'].revision)
394
375
# FIXME: This should raise a KeyError I think, rbc20051006
395
self.assertRaises(BzrError, inv.get_entry, b'file2id')
376
self.assertRaises(BzrError, inv.__getitem__, 'file2id')
397
378
def test_strict_commit(self):
398
379
"""Try and commit with unknown files and strict = True, should fail."""
399
from ..errors import StrictCommitFailed
380
from brzlib.errors import StrictCommitFailed
400
381
wt = self.make_branch_and_tree('.')
402
with open('hello', 'w') as f:
403
f.write('hello world')
383
with file('hello', 'w') as f: f.write('hello world')
405
with open('goodbye', 'w') as f:
406
f.write('goodbye cruel world!')
385
with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
407
386
self.assertRaises(StrictCommitFailed, wt.commit,
408
message='add hello but not goodbye', strict=True)
387
message='add hello but not goodbye', strict=True)
410
389
def test_strict_commit_without_unknowns(self):
411
390
"""Try and commit with no unknown files and strict = True,
413
392
wt = self.make_branch_and_tree('.')
415
with open('hello', 'w') as f:
416
f.write('hello world')
394
with file('hello', 'w') as f: f.write('hello world')
418
396
wt.commit(message='add hello', strict=True)
434
410
wt = self.make_branch_and_tree('.')
436
with open('hello', 'w') as f:
437
f.write('hello world')
412
with file('hello', 'w') as f: f.write('hello world')
439
414
wt.commit(message='add hello', strict=False)
441
416
def test_signed_commit(self):
443
import breezy.commit as commit
444
oldstrategy = breezy.gpg.GPGStrategy
418
import brzlib.commit as commit
419
oldstrategy = brzlib.gpg.GPGStrategy
445
420
wt = self.make_branch_and_tree('.')
446
421
branch = wt.branch
447
wt.commit("base", allow_pointless=True, rev_id=b'A')
448
self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
422
wt.commit("base", allow_pointless=True, rev_id='A')
423
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
450
from ..bzr.testament import Testament
425
from brzlib.testament import Testament
451
426
# monkey patch gpg signing mechanism
452
breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
453
conf = config.MemoryStack(b'''
427
brzlib.gpg.GPGStrategy = brzlib.gpg.LoopbackGPGStrategy
428
conf = config.MemoryStack('''
429
gpg_signing_command=cat -
454
430
create_signatures=always
456
432
commit.Commit(config_stack=conf).commit(
457
message="base", allow_pointless=True, rev_id=b'B',
433
message="base", allow_pointless=True, rev_id='B',
461
return breezy.gpg.LoopbackGPGStrategy(None).sign(
462
text, breezy.gpg.MODE_CLEAR)
436
return brzlib.gpg.LoopbackGPGStrategy(None).sign(text)
463
437
self.assertEqual(sign(Testament.from_revision(branch.repository,
464
b'B').as_short_text()),
465
branch.repository.get_signature_text(b'B'))
438
'B').as_short_text()),
439
branch.repository.get_signature_text('B'))
467
breezy.gpg.GPGStrategy = oldstrategy
441
brzlib.gpg.GPGStrategy = oldstrategy
469
443
def test_commit_failed_signature(self):
471
import breezy.commit as commit
472
oldstrategy = breezy.gpg.GPGStrategy
445
import brzlib.commit as commit
446
oldstrategy = brzlib.gpg.GPGStrategy
473
447
wt = self.make_branch_and_tree('.')
474
448
branch = wt.branch
475
wt.commit("base", allow_pointless=True, rev_id=b'A')
476
self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
449
wt.commit("base", allow_pointless=True, rev_id='A')
450
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
478
452
# monkey patch gpg signing mechanism
479
breezy.gpg.GPGStrategy = breezy.gpg.DisabledGPGStrategy
480
conf = config.MemoryStack(b'''
453
brzlib.gpg.GPGStrategy = brzlib.gpg.DisabledGPGStrategy
454
conf = config.MemoryStack('''
455
gpg_signing_command=cat -
481
456
create_signatures=always
483
self.assertRaises(breezy.gpg.SigningFailed,
458
self.assertRaises(SigningFailed,
484
459
commit.Commit(config_stack=conf).commit,
486
461
allow_pointless=True,
489
464
branch = Branch.open(self.get_url('.'))
490
self.assertEqual(branch.last_revision(), b'A')
491
self.assertFalse(branch.repository.has_revision(b'B'))
465
self.assertEqual(branch.last_revision(), 'A')
466
self.assertFalse(branch.repository.has_revision('B'))
493
breezy.gpg.GPGStrategy = oldstrategy
468
brzlib.gpg.GPGStrategy = oldstrategy
495
470
def test_commit_invokes_hooks(self):
496
import breezy.commit as commit
471
import brzlib.commit as commit
497
472
wt = self.make_branch_and_tree('.')
498
473
branch = wt.branch
501
475
def called(branch, rev_id):
502
476
calls.append('called')
503
breezy.ahook = called
477
brzlib.ahook = called
505
conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook')
479
conf = config.MemoryStack('post_commit=brzlib.ahook brzlib.ahook')
506
480
commit.Commit(config_stack=conf).commit(
507
message="base", allow_pointless=True, rev_id=b'A',
481
message = "base", allow_pointless=True, rev_id='A',
509
483
self.assertEqual(['called', 'called'], calls)
513
487
def test_commit_object_doesnt_set_nick(self):
514
488
# using the Commit object directly does not set the branch nick.
542
516
bound_tree = self.make_branch_and_tree('bound')
543
517
bound_tree.branch.bind(master_branch)
545
self.build_tree_contents(
546
[('bound/content_file', b'initial contents\n')])
519
self.build_tree_contents([('bound/content_file', 'initial contents\n')])
547
520
bound_tree.add(['content_file'])
548
521
bound_tree.commit(message='woo!')
550
other_bzrdir = master_branch.controldir.sprout('other')
523
other_bzrdir = master_branch.bzrdir.sprout('other')
551
524
other_tree = other_bzrdir.open_workingtree()
553
526
# do a commit to the other branch changing the content file so
554
527
# that our commit after merging will have a merged revision in the
555
528
# content file history.
556
self.build_tree_contents(
557
[('other/content_file', b'change in other\n')])
529
self.build_tree_contents([('other/content_file', 'change in other\n')])
558
530
other_tree.commit('change in other')
560
532
# do a merge into the bound branch from other, and then change the
561
533
# content file locally to force a new revision (rather than using the
562
534
# revision from other). This forces extra processing in commit.
563
535
bound_tree.merge_from_branch(other_tree.branch)
564
self.build_tree_contents(
565
[('bound/content_file', b'change in bound\n')])
536
self.build_tree_contents([('bound/content_file', 'change in bound\n')])
567
538
# before #34959 was fixed, this failed with 'revision not present in
568
539
# weave' when trying to implicitly push from the bound branch to the master
604
575
other_tree.rename_one('dirtorename', 'renameddir')
605
576
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
606
577
other_tree.rename_one('filetorename', 'renamedfile')
607
other_tree.rename_one(
608
'filetoreparent', 'renameddir/reparentedfile')
578
other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
609
579
other_tree.remove(['dirtoremove', 'filetoremove'])
610
580
self.build_tree_contents([
611
581
('other/newdir/', ),
612
('other/filetomodify', b'new content'),
613
('other/newfile', b'new file content')])
582
('other/filetomodify', 'new content'),
583
('other/newfile', 'new file content')])
614
584
other_tree.add('newfile')
615
585
other_tree.add('newdir/')
616
586
other_tree.commit('modify all sample files and dirs.')
664
637
tree = self.make_branch_and_tree('.')
665
638
self.build_tree(['a'])
667
tree.commit('added a', rev_id=b'a1')
640
tree.commit('added a', rev_id='a1')
669
rev = tree.branch.repository.get_revision(b'a1')
642
rev = tree.branch.repository.get_revision('a1')
670
643
timestamp = rev.timestamp
671
644
timestamp_1ms = round(timestamp, 3)
672
645
self.assertEqual(timestamp_1ms, timestamp)
674
def assertBasisTreeKind(self, kind, tree, path):
647
def assertBasisTreeKind(self, kind, tree, file_id):
675
648
basis = tree.basis_tree()
676
649
basis.lock_read()
678
self.assertEqual(kind, basis.kind(path))
651
self.assertEqual(kind, basis.kind(file_id))
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
655
def test_commit_kind_changes(self):
712
656
self.requireFeature(SymlinkFeature)
713
657
tree = self.make_branch_and_tree('.')
714
658
os.symlink('target', 'name')
715
tree.add('name', b'a-file-id')
659
tree.add('name', 'a-file-id')
716
660
tree.commit('Added a symlink')
717
self.assertBasisTreeKind('symlink', tree, 'name')
661
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
719
663
os.unlink('name')
720
664
self.build_tree(['name'])
721
665
tree.commit('Changed symlink to file')
722
self.assertBasisTreeKind('file', tree, 'name')
666
self.assertBasisTreeKind('file', tree, 'a-file-id')
724
668
os.unlink('name')
725
669
os.symlink('target', 'name')
726
670
tree.commit('file to symlink')
727
self.assertBasisTreeKind('symlink', tree, 'name')
671
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
729
673
os.unlink('name')
731
675
tree.commit('symlink to directory')
732
self.assertBasisTreeKind('directory', tree, 'name')
676
self.assertBasisTreeKind('directory', tree, 'a-file-id')
735
679
os.symlink('target', 'name')
736
680
tree.commit('directory to symlink')
737
self.assertBasisTreeKind('symlink', tree, 'name')
681
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
739
683
# prepare for directory <-> file tests
740
684
os.unlink('name')
742
686
tree.commit('symlink to directory')
743
self.assertBasisTreeKind('directory', tree, 'name')
687
self.assertBasisTreeKind('directory', tree, 'a-file-id')
746
690
self.build_tree(['name'])
747
691
tree.commit('Changed directory to file')
748
self.assertBasisTreeKind('file', tree, 'name')
692
self.assertBasisTreeKind('file', tree, 'a-file-id')
750
694
os.unlink('name')
752
696
tree.commit('file to directory')
753
self.assertBasisTreeKind('directory', tree, 'name')
697
self.assertBasisTreeKind('directory', tree, 'a-file-id')
755
699
def test_commit_unversioned_specified(self):
756
700
"""Commit should raise if specified files isn't in basis or worktree"""
816
759
tree = self.make_branch_and_tree('foo')
817
760
# pending merge would turn into a left parent
818
761
tree.commit('commit 1')
819
tree.add_parent_tree_id(b'example')
762
tree.add_parent_tree_id('example')
820
763
self.build_tree(['foo/bar', 'foo/baz'])
821
764
tree.add(['bar', 'baz'])
822
err = self.assertRaises(CannotCommitSelectedFileMerge,
823
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
765
err = self.assertRaises(errors.CannotCommitSelectedFileMerge,
766
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
824
767
self.assertEqual(['bar', 'baz'], err.files)
825
768
self.assertEqual('Selected-file commit of merges is not supported'
826
769
' yet: files bar, baz', str(err))
870
813
def test_multiple_authors(self):
871
814
tree = self.make_branch_and_tree('foo')
872
815
rev_id = tree.commit('commit 1',
873
authors=['John Doe <jdoe@example.com>',
874
'Jane Rey <jrey@example.com>'])
816
authors=['John Doe <jdoe@example.com>',
817
'Jane Rey <jrey@example.com>'])
875
818
rev = tree.branch.repository.get_revision(rev_id)
876
819
self.assertEqual('John Doe <jdoe@example.com>\n'
877
'Jane Rey <jrey@example.com>', rev.properties['authors'])
820
'Jane Rey <jrey@example.com>', rev.properties['authors'])
878
821
self.assertFalse('author' in rev.properties)
823
def test_author_and_authors_incompatible(self):
824
tree = self.make_branch_and_tree('foo')
825
self.assertRaises(AssertionError, tree.commit, 'commit 1',
826
authors=['John Doe <jdoe@example.com>',
827
'Jane Rey <jrey@example.com>'],
828
author="Jack Me <jme@example.com>")
880
830
def test_author_with_newline_rejected(self):
881
831
tree = self.make_branch_and_tree('foo')
882
832
self.assertRaises(AssertionError, tree.commit, 'commit 1',
883
authors=['John\nDoe <jdoe@example.com>'])
833
authors=['John\nDoe <jdoe@example.com>'])
885
835
def test_commit_with_checkout_and_branch_sharing_repo(self):
886
836
repo = self.make_repository('repo', shared=True)
887
837
# make_branch_and_tree ignores shared repos
888
838
branch = controldir.ControlDir.create_branch_convenience('repo/branch')
889
839
tree2 = branch.create_checkout('repo/tree2')
890
tree2.commit('message', rev_id=b'rev1')
891
self.assertTrue(tree2.branch.repository.has_revision(b'rev1'))
894
class FilterExcludedTests(TestCase):
896
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'])))
905
def test_add_file_excluded(self):
908
'fid', (None, 'newpath'),
909
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
910
('file', 'file'), (True, True))]
911
self.assertEqual([], list(filter_excluded(changes, ['newpath'])))
913
def test_delete_file_excluded(self):
916
'fid', ('somepath', None),
917
0, (False, None), ('pid', None), ('newpath', None),
918
('file', None), (True, None))]
919
self.assertEqual([], list(filter_excluded(changes, ['somepath'])))
921
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))]
927
self.assertEqual([], list(filter_excluded(changes, ['oldpath'])))
928
self.assertEqual([], list(filter_excluded(changes, ['newpath'])))
840
tree2.commit('message', rev_id='rev1')
841
self.assertTrue(tree2.branch.repository.has_revision('rev1'))