86
86
"""Commit and check two versions of a single file."""
87
87
wt = self.make_branch_and_tree('.')
89
with open('hello', 'w') as f: f.write('hello world')
89
with open('hello', 'w') as f:
90
f.write('hello world')
91
92
rev1 = wt.commit(message='add hello')
93
with open('hello', 'w') as f: f.write('version 2')
94
with open('hello', 'w') as f:
94
96
rev2 = wt.commit(message='commit 2')
96
98
eq = self.assertEqual
114
116
"""Attempt a lossy commit to a native branch."""
115
117
wt = self.make_branch_and_tree('.')
117
with open('hello', 'w') as f: f.write('hello world')
119
with open('hello', 'w') as f:
120
f.write('hello world')
119
122
revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
120
123
self.assertEqual(b'revid', revid)
123
126
"""Attempt a lossy commit to a foreign branch."""
124
127
test_foreign.register_dummy_foreign_for_test(self)
125
128
wt = self.make_branch_and_tree('.',
126
format=test_foreign.DummyForeignVcsDirFormat())
129
format=test_foreign.DummyForeignVcsDirFormat())
128
with open('hello', 'w') as f: f.write('hello world')
131
with open('hello', 'w') as f:
132
f.write('hello world')
130
134
revid = wt.commit(message='add hello', lossy=True,
131
timestamp=1302659388, timezone=0)
135
timestamp=1302659388, timezone=0)
132
136
self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
134
138
def test_commit_bound_lossy_foreign(self):
135
139
"""Attempt a lossy commit to a bzr branch bound to a foreign branch."""
136
140
test_foreign.register_dummy_foreign_for_test(self)
137
141
foreign_branch = self.make_branch('foreign',
138
format=test_foreign.DummyForeignVcsDirFormat())
142
format=test_foreign.DummyForeignVcsDirFormat())
139
143
wt = foreign_branch.create_checkout("local")
141
with open('local/hello', 'w') as f: f.write('hello world')
145
with open('local/hello', 'w') as f:
146
f.write('hello world')
143
148
revid = wt.commit(message='add hello', lossy=True,
144
timestamp=1302659388, timezone=0)
149
timestamp=1302659388, timezone=0)
145
150
self.assertEqual(b'dummy-v1:1302659388-0-0', revid)
146
151
self.assertEqual(b'dummy-v1:1302659388-0-0',
147
foreign_branch.last_revision())
152
foreign_branch.last_revision())
148
153
self.assertEqual(b'dummy-v1:1302659388-0-0',
149
wt.branch.last_revision())
154
wt.branch.last_revision())
151
156
def test_missing_commit(self):
152
157
"""Test a commit with a missing file"""
153
158
wt = self.make_branch_and_tree('.')
155
with open('hello', 'w') as f: f.write('hello world')
160
with open('hello', 'w') as f:
161
f.write('hello world')
156
162
wt.add(['hello'], [b'hello-id'])
157
163
wt.commit(message='add hello')
180
186
self.build_tree(['annotate/', 'annotate/foo.py',
181
187
'olive/', 'olive/dialog.py'
183
189
wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
184
190
wt.commit(message='add files')
185
191
wt.rename_one("olive/dialog.py", "aaa")
190
196
"""Commit refuses unless there are changes or it's forced."""
191
197
wt = self.make_branch_and_tree('.')
193
with open('hello', 'w') as f: f.write('hello')
199
with open('hello', 'w') as f:
194
201
wt.add(['hello'])
195
202
wt.commit(message='add hello')
196
203
self.assertEqual(b.revno(), 1)
216
223
"""Selective commit in tree with deletions"""
217
224
wt = self.make_branch_and_tree('.')
219
with open('hello', 'w') as f: f.write('hello')
220
with open('buongia', 'w') as f: f.write('buongia')
226
with open('hello', 'w') as f:
228
with open('buongia', 'w') as f:
221
230
wt.add(['hello', 'buongia'],
222
[b'hello-id', b'buongia-id'])
231
[b'hello-id', b'buongia-id'])
223
232
wt.commit(message='add files',
224
rev_id=b'test@rev-1')
233
rev_id=b'test@rev-1')
226
235
os.remove('hello')
227
with open('buongia', 'w') as f: f.write('new text')
236
with open('buongia', 'w') as f:
228
238
wt.commit(message='update text',
229
specific_files=['buongia'],
230
allow_pointless=False,
231
rev_id=b'test@rev-2')
239
specific_files=['buongia'],
240
allow_pointless=False,
241
rev_id=b'test@rev-2')
233
243
wt.commit(message='remove hello',
234
specific_files=['hello'],
235
allow_pointless=False,
236
rev_id=b'test@rev-3')
244
specific_files=['hello'],
245
allow_pointless=False,
246
rev_id=b'test@rev-3')
238
248
eq = self.assertEqual
260
270
tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
262
272
tree.rename_one('hello', 'fruity')
263
tree.commit(message='renamed', rev_id=b'test@rev-2', allow_pointless=False)
273
tree.commit(message='renamed', rev_id=b'test@rev-2',
274
allow_pointless=False)
265
276
eq = self.assertEqual
266
277
tree1 = b.repository.revision_tree(b'test@rev-1')
317
328
self.check_tree_shape(wt,
318
['a/', 'a/hello', 'a/b/'])
329
['a/', 'a/hello', 'a/b/'])
319
330
self.check_tree_shape(b.repository.revision_tree(r3),
320
['a/', 'a/hello', 'a/b/'])
331
['a/', 'a/hello', 'a/b/'])
339
350
"""Commit with a removed file"""
340
351
wt = self.make_branch_and_tree('.')
342
with open('hello', 'w') as f: f.write('hello world')
353
with open('hello', 'w') as f:
354
f.write('hello world')
343
355
wt.add(['hello'], [b'hello-id'])
344
356
wt.commit(message='add hello')
345
357
wt.remove('hello')
356
368
for i in range(4):
357
with open('hello', 'w') as f: f.write((str(i) * 4) + '\n')
369
with open('hello', 'w') as f:
370
f.write((str(i) * 4) + '\n')
359
372
wt.add(['hello'], [b'hello-id'])
360
rev_id = b'test@rev-%d' % (i+1)
373
rev_id = b'test@rev-%d' % (i + 1)
361
374
rev_ids.append(rev_id)
362
wt.commit(message='rev %d' % (i+1),
375
wt.commit(message='rev %d' % (i + 1),
364
377
for i in range(4):
365
self.assertThat(rev_ids[:i+1],
366
MatchesAncestry(b.repository, rev_ids[i]))
378
self.assertThat(rev_ids[:i + 1],
379
MatchesAncestry(b.repository, rev_ids[i]))
368
381
def test_commit_new_subdir_child_selective(self):
369
382
wt = self.make_branch_and_tree('.')
371
384
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
372
385
wt.add(['dir', 'dir/file1', 'dir/file2'],
373
[b'dirid', b'file1id', b'file2id'])
386
[b'dirid', b'file1id', b'file2id'])
374
387
wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
375
388
inv = b.repository.get_inventory(b'1')
376
389
self.assertEqual(b'1', inv.get_entry(b'dirid').revision)
383
396
from ..errors import StrictCommitFailed
384
397
wt = self.make_branch_and_tree('.')
386
with open('hello', 'w') as f: f.write('hello world')
399
with open('hello', 'w') as f:
400
f.write('hello world')
388
with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
402
with open('goodbye', 'w') as f:
403
f.write('goodbye cruel world!')
389
404
self.assertRaises(StrictCommitFailed, wt.commit,
390
message='add hello but not goodbye', strict=True)
405
message='add hello but not goodbye', strict=True)
392
407
def test_strict_commit_without_unknowns(self):
393
408
"""Try and commit with no unknown files and strict = True,
395
410
wt = self.make_branch_and_tree('.')
397
with open('hello', 'w') as f: f.write('hello world')
412
with open('hello', 'w') as f:
413
f.write('hello world')
399
415
wt.commit(message='add hello', strict=True)
402
418
"""Try and commit with unknown files and strict = False, should work."""
403
419
wt = self.make_branch_and_tree('.')
405
with open('hello', 'w') as f: f.write('hello world')
421
with open('hello', 'w') as f:
422
f.write('hello world')
407
with open('goodbye', 'w') as f: f.write('goodbye cruel world!')
424
with open('goodbye', 'w') as f:
425
f.write('goodbye cruel world!')
408
426
wt.commit(message='add hello but not goodbye', strict=False)
410
428
def test_nonstrict_commit_without_unknowns(self):
434
453
commit.Commit(config_stack=conf).commit(
435
454
message="base", allow_pointless=True, rev_id=b'B',
438
458
return breezy.gpg.LoopbackGPGStrategy(None).sign(
439
text, breezy.gpg.MODE_CLEAR)
459
text, breezy.gpg.MODE_CLEAR)
440
460
self.assertEqual(sign(Testament.from_revision(branch.repository,
441
461
b'B').as_short_text()),
442
462
branch.repository.get_signature_text(b'B'))
474
494
wt = self.make_branch_and_tree('.')
475
495
branch = wt.branch
477
498
def called(branch, rev_id):
478
499
calls.append('called')
479
500
breezy.ahook = called
481
502
conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook')
482
503
commit.Commit(config_stack=conf).commit(
483
message = "base", allow_pointless=True, rev_id=b'A',
504
message="base", allow_pointless=True, rev_id=b'A',
485
506
self.assertEqual(['called', 'called'], calls)
518
539
bound_tree = self.make_branch_and_tree('bound')
519
540
bound_tree.branch.bind(master_branch)
521
self.build_tree_contents([('bound/content_file', b'initial contents\n')])
542
self.build_tree_contents(
543
[('bound/content_file', b'initial contents\n')])
522
544
bound_tree.add(['content_file'])
523
545
bound_tree.commit(message='woo!')
528
550
# do a commit to the other branch changing the content file so
529
551
# that our commit after merging will have a merged revision in the
530
552
# content file history.
531
self.build_tree_contents([('other/content_file', b'change in other\n')])
553
self.build_tree_contents(
554
[('other/content_file', b'change in other\n')])
532
555
other_tree.commit('change in other')
534
557
# do a merge into the bound branch from other, and then change the
535
558
# content file locally to force a new revision (rather than using the
536
559
# revision from other). This forces extra processing in commit.
537
560
bound_tree.merge_from_branch(other_tree.branch)
538
self.build_tree_contents([('bound/content_file', b'change in bound\n')])
561
self.build_tree_contents(
562
[('bound/content_file', b'change in bound\n')])
540
564
# before #34959 was fixed, this failed with 'revision not present in
541
565
# weave' when trying to implicitly push from the bound branch to the master
577
601
other_tree.rename_one('dirtorename', 'renameddir')
578
602
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
579
603
other_tree.rename_one('filetorename', 'renamedfile')
580
other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
604
other_tree.rename_one(
605
'filetoreparent', 'renameddir/reparentedfile')
581
606
other_tree.remove(['dirtoremove', 'filetoremove'])
582
607
self.build_tree_contents([
583
608
('other/newdir/', ),
746
771
cb = self.Callback(u'commit 2', self)
747
772
repository = tree.branch.repository
748
773
# simulate network failure
749
775
def raise_(self, arg, arg2, arg3=None, arg4=None):
750
776
raise errors.NoSuchFile('foo')
751
777
repository.add_inventory = raise_
762
788
self.build_tree(['foo/bar', 'foo/baz'])
763
789
tree.add(['bar', 'baz'])
764
790
err = self.assertRaises(CannotCommitSelectedFileMerge,
765
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
791
tree.commit, 'commit 2', specific_files=['bar', 'baz'])
766
792
self.assertEqual(['bar', 'baz'], err.files)
767
793
self.assertEqual('Selected-file commit of merges is not supported'
768
794
' yet: files bar, baz', str(err))
812
838
def test_multiple_authors(self):
813
839
tree = self.make_branch_and_tree('foo')
814
840
rev_id = tree.commit('commit 1',
815
authors=['John Doe <jdoe@example.com>',
816
'Jane Rey <jrey@example.com>'])
841
authors=['John Doe <jdoe@example.com>',
842
'Jane Rey <jrey@example.com>'])
817
843
rev = tree.branch.repository.get_revision(rev_id)
818
844
self.assertEqual('John Doe <jdoe@example.com>\n'
819
'Jane Rey <jrey@example.com>', rev.properties['authors'])
845
'Jane Rey <jrey@example.com>', rev.properties['authors'])
820
846
self.assertFalse('author' in rev.properties)
822
848
def test_author_with_newline_rejected(self):
823
849
tree = self.make_branch_and_tree('foo')
824
850
self.assertRaises(AssertionError, tree.commit, 'commit 1',
825
authors=['John\nDoe <jdoe@example.com>'])
851
authors=['John\nDoe <jdoe@example.com>'])
827
853
def test_commit_with_checkout_and_branch_sharing_repo(self):
828
854
repo = self.make_repository('repo', shared=True)
840
866
('fid', (None, 'newpath'),
841
867
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
842
868
('file', 'file'), (True, True))]
843
self.assertEqual(changes, list(filter_excluded(changes, ['otherpath'])))
869
self.assertEqual(changes, list(
870
filter_excluded(changes, ['otherpath'])))
845
872
def test_add_file_excluded(self):