88
88
"""Commit and check two versions of a single file."""
89
89
wt = self.make_branch_and_tree('.')
91
with open('hello', 'w') as f: f.write('hello world')
91
with open('hello', 'w') as f:
92
f.write('hello world')
93
94
rev1 = wt.commit(message='add hello')
95
with open('hello', 'w') as f: f.write('version 2')
96
with open('hello', 'w') as f:
96
98
rev2 = wt.commit(message='commit 2')
98
100
eq = self.assertEqual
116
118
"""Attempt a lossy commit to a native branch."""
117
119
wt = self.make_branch_and_tree('.')
119
with open('hello', 'w') as f: f.write('hello world')
121
with open('hello', 'w') as f:
122
f.write('hello world')
121
124
revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
122
125
self.assertEqual(b'revid', revid)
125
128
"""Attempt a lossy commit to a foreign branch."""
126
129
test_foreign.register_dummy_foreign_for_test(self)
127
130
wt = self.make_branch_and_tree('.',
128
format=test_foreign.DummyForeignVcsDirFormat())
131
format=test_foreign.DummyForeignVcsDirFormat())
130
with open('hello', 'w') as f: f.write('hello world')
133
with open('hello', 'w') as f:
134
f.write('hello world')
132
136
revid = wt.commit(message='add hello', lossy=True,
133
timestamp=1302659388, timezone=0)
137
timestamp=1302659388, timezone=0)
134
138
self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
136
140
def test_commit_bound_lossy_foreign(self):
137
141
"""Attempt a lossy commit to a bzr branch bound to a foreign branch."""
138
142
test_foreign.register_dummy_foreign_for_test(self)
139
143
foreign_branch = self.make_branch('foreign',
140
format=test_foreign.DummyForeignVcsDirFormat())
144
format=test_foreign.DummyForeignVcsDirFormat())
141
145
wt = foreign_branch.create_checkout("local")
143
with open('local/hello', 'w') as f: f.write('hello world')
147
with open('local/hello', 'w') as f:
148
f.write('hello world')
145
150
revid = wt.commit(message='add hello', lossy=True,
146
timestamp=1302659388, timezone=0)
151
timestamp=1302659388, timezone=0)
147
152
self.assertEqual(b'dummy-v1:1302659388-0-0', revid)
148
153
self.assertEqual(b'dummy-v1:1302659388-0-0',
149
foreign_branch.last_revision())
154
foreign_branch.last_revision())
150
155
self.assertEqual(b'dummy-v1:1302659388-0-0',
151
wt.branch.last_revision())
156
wt.branch.last_revision())
153
158
def test_missing_commit(self):
154
159
"""Test a commit with a missing file"""
155
160
wt = self.make_branch_and_tree('.')
157
with open('hello', 'w') as f: f.write('hello world')
162
with open('hello', 'w') as f:
163
f.write('hello world')
158
164
wt.add(['hello'], [b'hello-id'])
159
165
wt.commit(message='add hello')
182
188
self.build_tree(['annotate/', 'annotate/foo.py',
183
189
'olive/', 'olive/dialog.py'
185
191
wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
186
192
wt.commit(message='add files')
187
193
wt.rename_one("olive/dialog.py", "aaa")
192
198
"""Commit refuses unless there are changes or it's forced."""
193
199
wt = self.make_branch_and_tree('.')
195
with open('hello', 'w') as f: f.write('hello')
201
with open('hello', 'w') as f:
196
203
wt.add(['hello'])
197
204
wt.commit(message='add hello')
198
205
self.assertEqual(b.revno(), 1)
218
225
"""Selective commit in tree with deletions"""
219
226
wt = self.make_branch_and_tree('.')
221
with open('hello', 'w') as f: f.write('hello')
222
with open('buongia', 'w') as f: f.write('buongia')
228
with open('hello', 'w') as f:
230
with open('buongia', 'w') as f:
223
232
wt.add(['hello', 'buongia'],
224
[b'hello-id', b'buongia-id'])
233
[b'hello-id', b'buongia-id'])
225
234
wt.commit(message='add files',
226
rev_id=b'test@rev-1')
235
rev_id=b'test@rev-1')
228
237
os.remove('hello')
229
with open('buongia', 'w') as f: f.write('new text')
238
with open('buongia', 'w') as f:
230
240
wt.commit(message='update text',
231
specific_files=['buongia'],
232
allow_pointless=False,
233
rev_id=b'test@rev-2')
241
specific_files=['buongia'],
242
allow_pointless=False,
243
rev_id=b'test@rev-2')
235
245
wt.commit(message='remove hello',
236
specific_files=['hello'],
237
allow_pointless=False,
238
rev_id=b'test@rev-3')
246
specific_files=['hello'],
247
allow_pointless=False,
248
rev_id=b'test@rev-3')
240
250
eq = self.assertEqual
262
272
tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
264
274
tree.rename_one('hello', 'fruity')
265
tree.commit(message='renamed', rev_id=b'test@rev-2', allow_pointless=False)
275
tree.commit(message='renamed', rev_id=b'test@rev-2',
276
allow_pointless=False)
267
278
eq = self.assertEqual
268
279
tree1 = b.repository.revision_tree(b'test@rev-1')
319
330
self.check_tree_shape(wt,
320
['a/', 'a/hello', 'a/b/'])
331
['a/', 'a/hello', 'a/b/'])
321
332
self.check_tree_shape(b.repository.revision_tree(r3),
322
['a/', 'a/hello', 'a/b/'])
333
['a/', 'a/hello', 'a/b/'])
341
352
"""Commit with a removed file"""
342
353
wt = self.make_branch_and_tree('.')
344
with open('hello', 'w') as f: f.write('hello world')
355
with open('hello', 'w') as f:
356
f.write('hello world')
345
357
wt.add(['hello'], [b'hello-id'])
346
358
wt.commit(message='add hello')
347
359
wt.remove('hello')
358
370
for i in range(4):
359
with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
371
with open('hello', 'w') as f:
372
f.write((str(i) * 4) + '\n')
361
374
wt.add(['hello'], [b'hello-id'])
362
rev_id = b'test@rev-%d' % (i+1)
375
rev_id = b'test@rev-%d' % (i + 1)
363
376
rev_ids.append(rev_id)
364
wt.commit(message='rev %d' % (i+1),
377
wt.commit(message='rev %d' % (i + 1),
366
379
for i in range(4):
367
self.assertThat(rev_ids[:i+1],
368
MatchesAncestry(b.repository, rev_ids[i]))
380
self.assertThat(rev_ids[:i + 1],
381
MatchesAncestry(b.repository, rev_ids[i]))
370
383
def test_commit_new_subdir_child_selective(self):
371
384
wt = self.make_branch_and_tree('.')
373
386
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
374
387
wt.add(['dir', 'dir/file1', 'dir/file2'],
375
[b'dirid', b'file1id', b'file2id'])
388
[b'dirid', b'file1id', b'file2id'])
376
389
wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
377
390
inv = b.repository.get_inventory(b'1')
378
391
self.assertEqual(b'1', inv.get_entry(b'dirid').revision)
385
398
from ..errors import StrictCommitFailed
386
399
wt = self.make_branch_and_tree('.')
388
with open('hello', 'w') as f: f.write('hello world')
401
with open('hello', 'w') as f:
402
f.write('hello world')
390
with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
404
with open('goodbye', 'w') as f:
405
f.write('goodbye cruel world!')
391
406
self.assertRaises(StrictCommitFailed, wt.commit,
392
message='add hello but not goodbye', strict=True)
407
message='add hello but not goodbye', strict=True)
394
409
def test_strict_commit_without_unknowns(self):
395
410
"""Try and commit with no unknown files and strict = True,
397
412
wt = self.make_branch_and_tree('.')
399
with open('hello', 'w') as f: f.write('hello world')
414
with open('hello', 'w') as f:
415
f.write('hello world')
401
417
wt.commit(message='add hello', strict=True)
404
420
"""Try and commit with unknown files and strict = False, should work."""
405
421
wt = self.make_branch_and_tree('.')
407
with open('hello', 'w') as f: f.write('hello world')
423
with open('hello', 'w') as f:
424
f.write('hello world')
409
with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
426
with open('goodbye', 'w') as f:
427
f.write('goodbye cruel world!')
410
428
wt.commit(message='add hello but not goodbye', strict=False)
412
430
def test_nonstrict_commit_without_unknowns(self):
427
446
wt.commit("base", allow_pointless=True, rev_id=b'A')
428
447
self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
430
from ..testament import Testament
449
from ..bzr.testament import Testament
431
450
# monkey patch gpg signing mechanism
432
451
breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
433
452
conf = config.MemoryStack(b'''
436
455
commit.Commit(config_stack=conf).commit(
437
456
message="base", allow_pointless=True, rev_id=b'B',
440
460
return breezy.gpg.LoopbackGPGStrategy(None).sign(
441
text, breezy.gpg.MODE_CLEAR)
461
text, breezy.gpg.MODE_CLEAR)
442
462
self.assertEqual(sign(Testament.from_revision(branch.repository,
443
463
b'B').as_short_text()),
444
464
branch.repository.get_signature_text(b'B'))
476
496
wt = self.make_branch_and_tree('.')
477
497
branch = wt.branch
479
500
def called(branch, rev_id):
480
501
calls.append('called')
481
502
breezy.ahook = called
483
504
conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook')
484
505
commit.Commit(config_stack=conf).commit(
485
message = "base", allow_pointless=True, rev_id=b'A',
506
message="base", allow_pointless=True, rev_id=b'A',
487
508
self.assertEqual(['called', 'called'], calls)
520
541
bound_tree = self.make_branch_and_tree('bound')
521
542
bound_tree.branch.bind(master_branch)
523
self.build_tree_contents([('bound/content_file', b'initial contents\n')])
544
self.build_tree_contents(
545
[('bound/content_file', b'initial contents\n')])
524
546
bound_tree.add(['content_file'])
525
547
bound_tree.commit(message='woo!')
530
552
# do a commit to the other branch changing the content file so
531
553
# that our commit after merging will have a merged revision in the
532
554
# content file history.
533
self.build_tree_contents([('other/content_file', b'change in other\n')])
555
self.build_tree_contents(
556
[('other/content_file', b'change in other\n')])
534
557
other_tree.commit('change in other')
536
559
# do a merge into the bound branch from other, and then change the
537
560
# content file locally to force a new revision (rather than using the
538
561
# revision from other). This forces extra processing in commit.
539
562
bound_tree.merge_from_branch(other_tree.branch)
540
self.build_tree_contents([('bound/content_file', b'change in bound\n')])
563
self.build_tree_contents(
564
[('bound/content_file', b'change in bound\n')])
542
566
# before #34959 was fixed, this failed with 'revision not present in
543
567
# weave' when trying to implicitly push from the bound branch to the master
579
603
other_tree.rename_one('dirtorename', 'renameddir')
580
604
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
581
605
other_tree.rename_one('filetorename', 'renamedfile')
582
other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
606
other_tree.rename_one(
607
'filetoreparent', 'renameddir/reparentedfile')
583
608
other_tree.remove(['dirtoremove', 'filetoremove'])
584
609
self.build_tree_contents([
585
610
('other/newdir/', ),
777
802
cb = self.Callback(u'commit 2', self)
778
803
repository = tree.branch.repository
779
804
# simulate network failure
780
806
def raise_(self, arg, arg2, arg3=None, arg4=None):
781
807
raise errors.NoSuchFile('foo')
782
808
repository.add_inventory = raise_
793
819
self.build_tree(['foo/bar', 'foo/baz'])
794
820
tree.add(['bar', 'baz'])
795
821
err = self.assertRaises(CannotCommitSelectedFileMerge,
796
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
822
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
797
823
self.assertEqual(['bar', 'baz'], err.files)
798
824
self.assertEqual('Selected-file commit of merges is not supported'
799
825
' yet: files bar, baz', str(err))
843
869
def test_multiple_authors(self):
844
870
tree = self.make_branch_and_tree('foo')
845
871
rev_id = tree.commit('commit 1',
846
authors=['John Doe <jdoe@example.com>',
847
'Jane Rey <jrey@example.com>'])
872
authors=['John Doe <jdoe@example.com>',
873
'Jane Rey <jrey@example.com>'])
848
874
rev = tree.branch.repository.get_revision(rev_id)
849
875
self.assertEqual('John Doe <jdoe@example.com>\n'
850
'Jane Rey <jrey@example.com>', rev.properties['authors'])
876
'Jane Rey <jrey@example.com>', rev.properties['authors'])
851
877
self.assertFalse('author' in rev.properties)
853
879
def test_author_with_newline_rejected(self):
854
880
tree = self.make_branch_and_tree('foo')
855
881
self.assertRaises(AssertionError, tree.commit, 'commit 1',
856
authors=['John\nDoe <jdoe@example.com>'])
882
authors=['John\nDoe <jdoe@example.com>'])
858
884
def test_commit_with_checkout_and_branch_sharing_repo(self):
859
885
repo = self.make_repository('repo', shared=True)
871
897
('fid', (None, 'newpath'),
872
898
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
873
899
('file', 'file'), (True, True))]
874
self.assertEqual(changes, list(filter_excluded(changes, ['otherpath'])))
900
self.assertEqual(changes, list(
901
filter_excluded(changes, ['otherpath'])))
876
903
def test_add_file_excluded(self):