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
[b'hello-id', b'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
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
eq(tree1.id2path(b'hello-id'), 'hello')
269
eq(tree1.id2path(b'hello-id'), b'hello')
284
270
eq(tree1.get_file_text('hello'), b'contents of hello\n')
285
271
self.assertFalse(tree1.has_filename('fruity'))
286
272
self.check_tree_shape(tree1, ['hello'])
353
339
"""Commit with a removed file"""
354
340
wt = self.make_branch_and_tree('.')
356
with open('hello', 'w') as f:
357
f.write('hello world')
342
with open('hello', 'w') as f: f.write('hello world')
358
343
wt.add(['hello'], [b'hello-id'])
359
344
wt.commit(message='add hello')
360
345
wt.remove('hello')
361
346
wt.commit('removed hello', rev_id=b'rev2')
363
348
tree = b.repository.revision_tree(b'rev2')
364
self.assertFalse(tree.has_filename('hello'))
349
self.assertFalse(tree.has_id(b'hello-id'))
366
351
def test_committed_ancestry(self):
367
352
"""Test commit appends revisions to ancestry."""
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
[b'dirid', b'file1id', b'file2id'])
390
374
wt.commit('dir/file1', specific_files=['dir/file1'], rev_id=b'1')
391
375
inv = b.repository.get_inventory(b'1')
392
376
self.assertEqual(b'1', inv.get_entry(b'dirid').revision)
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)
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('.')
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)
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'])))