82
89
"""Commit and check two versions of a single file."""
83
90
wt = self.make_branch_and_tree('.')
85
with file('hello', 'w') as f: f.write('hello world')
92
with open('hello', 'w') as f:
93
f.write('hello world')
87
95
rev1 = wt.commit(message='add hello')
88
file_id = wt.path2id('hello')
90
with file('hello', 'w') as f: f.write('version 2')
97
with open('hello', 'w') as f:
91
99
rev2 = wt.commit(message='commit 2')
93
eq = self.assertEquals
101
eq = self.assertEqual
95
103
rev = b.repository.get_revision(rev1)
96
104
eq(rev.message, 'add hello')
98
106
tree1 = b.repository.revision_tree(rev1)
100
text = tree1.get_file_text(file_id)
108
text = tree1.get_file_text('hello')
102
self.assertEqual('hello world', text)
110
self.assertEqual(b'hello world', text)
104
112
tree2 = b.repository.revision_tree(rev2)
105
113
tree2.lock_read()
106
text = tree2.get_file_text(file_id)
114
text = tree2.get_file_text('hello')
108
self.assertEqual('version 2', text)
116
self.assertEqual(b'version 2', text)
110
118
def test_commit_lossy_native(self):
111
119
"""Attempt a lossy commit to a native branch."""
112
120
wt = self.make_branch_and_tree('.')
114
with file('hello', 'w') as f: f.write('hello world')
122
with open('hello', 'w') as f:
123
f.write('hello world')
116
revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
117
self.assertEquals('revid', revid)
125
revid = wt.commit(message='add hello', rev_id=b'revid', lossy=True)
126
self.assertEqual(b'revid', revid)
119
128
def test_commit_lossy_foreign(self):
120
129
"""Attempt a lossy commit to a foreign branch."""
121
130
test_foreign.register_dummy_foreign_for_test(self)
122
131
wt = self.make_branch_and_tree('.',
123
format=test_foreign.DummyForeignVcsDirFormat())
132
format=test_foreign.DummyForeignVcsDirFormat())
125
with file('hello', 'w') as f: f.write('hello world')
134
with open('hello', 'w') as f:
135
f.write('hello world')
127
137
revid = wt.commit(message='add hello', lossy=True,
128
timestamp=1302659388, timezone=0)
129
self.assertEquals('dummy-v1:1302659388.0-0-UNKNOWN', revid)
138
timestamp=1302659388, timezone=0)
139
self.assertEqual(b'dummy-v1:1302659388-0-UNKNOWN', revid)
131
141
def test_commit_bound_lossy_foreign(self):
132
142
"""Attempt a lossy commit to a bzr branch bound to a foreign branch."""
133
143
test_foreign.register_dummy_foreign_for_test(self)
134
144
foreign_branch = self.make_branch('foreign',
135
format=test_foreign.DummyForeignVcsDirFormat())
145
format=test_foreign.DummyForeignVcsDirFormat())
136
146
wt = foreign_branch.create_checkout("local")
138
with file('local/hello', 'w') as f: f.write('hello world')
148
with open('local/hello', 'w') as f:
149
f.write('hello world')
140
151
revid = wt.commit(message='add hello', lossy=True,
141
timestamp=1302659388, timezone=0)
142
self.assertEquals('dummy-v1:1302659388.0-0-0', revid)
143
self.assertEquals('dummy-v1:1302659388.0-0-0',
144
foreign_branch.last_revision())
145
self.assertEquals('dummy-v1:1302659388.0-0-0',
146
wt.branch.last_revision())
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())
148
159
def test_missing_commit(self):
149
160
"""Test a commit with a missing file"""
150
161
wt = self.make_branch_and_tree('.')
152
with file('hello', 'w') as f: f.write('hello world')
153
wt.add(['hello'], ['hello-id'])
163
with open('hello', 'w') as f:
164
f.write('hello world')
165
wt.add(['hello'], [b'hello-id'])
154
166
wt.commit(message='add hello')
156
168
os.remove('hello')
157
169
reporter = CapturingReporter()
158
wt.commit('removed hello', rev_id='rev2', reporter=reporter)
170
wt.commit('removed hello', rev_id=b'rev2', reporter=reporter)
160
172
[('missing', u'hello'), ('deleted', u'hello')],
163
tree = b.repository.revision_tree('rev2')
164
self.assertFalse(tree.has_id('hello-id'))
175
tree = b.repository.revision_tree(b'rev2')
176
self.assertFalse(tree.has_filename('hello'))
166
178
def test_partial_commit_move(self):
167
179
"""Test a partial commit where a file was renamed but not committed.
177
189
self.build_tree(['annotate/', 'annotate/foo.py',
178
190
'olive/', 'olive/dialog.py'
180
192
wt.add(['annotate', 'olive', 'annotate/foo.py', 'olive/dialog.py'])
181
193
wt.commit(message='add files')
182
194
wt.rename_one("olive/dialog.py", "aaa")
183
self.build_tree_contents([('annotate/foo.py', 'modified\n')])
195
self.build_tree_contents([('annotate/foo.py', b'modified\n')])
184
196
wt.commit('renamed hello', specific_files=["annotate"])
186
198
def test_pointless_commit(self):
187
199
"""Commit refuses unless there are changes or it's forced."""
188
200
wt = self.make_branch_and_tree('.')
190
with file('hello', 'w') as f: f.write('hello')
202
with open('hello', 'w') as f:
191
204
wt.add(['hello'])
192
205
wt.commit(message='add hello')
193
self.assertEquals(b.revno(), 1)
206
self.assertEqual(b.revno(), 1)
194
207
self.assertRaises(PointlessCommit,
197
210
allow_pointless=False)
198
self.assertEquals(b.revno(), 1)
211
self.assertEqual(b.revno(), 1)
200
213
def test_commit_empty(self):
201
214
"""Commiting an empty tree works."""
207
220
message='empty tree',
208
221
allow_pointless=False)
209
222
wt.commit(message='empty tree', allow_pointless=True)
210
self.assertEquals(b.revno(), 2)
223
self.assertEqual(b.revno(), 2)
212
225
def test_selective_delete(self):
213
226
"""Selective commit in tree with deletions"""
214
227
wt = self.make_branch_and_tree('.')
216
with file('hello', 'w') as f: f.write('hello')
217
with file('buongia', 'w') as f: f.write('buongia')
229
with open('hello', 'w') as f:
231
with open('buongia', 'w') as f:
218
233
wt.add(['hello', 'buongia'],
219
['hello-id', 'buongia-id'])
234
[b'hello-id', b'buongia-id'])
220
235
wt.commit(message='add files',
236
rev_id=b'test@rev-1')
223
238
os.remove('hello')
224
with file('buongia', 'w') as f: f.write('new text')
239
with open('buongia', 'w') as f:
225
241
wt.commit(message='update text',
226
specific_files=['buongia'],
227
allow_pointless=False,
242
specific_files=['buongia'],
243
allow_pointless=False,
244
rev_id=b'test@rev-2')
230
246
wt.commit(message='remove hello',
231
specific_files=['hello'],
232
allow_pointless=False,
247
specific_files=['hello'],
248
allow_pointless=False,
249
rev_id=b'test@rev-3')
235
eq = self.assertEquals
251
eq = self.assertEqual
238
tree2 = b.repository.revision_tree('test@rev-2')
254
tree2 = b.repository.revision_tree(b'test@rev-2')
239
255
tree2.lock_read()
240
256
self.addCleanup(tree2.unlock)
241
257
self.assertTrue(tree2.has_filename('hello'))
242
self.assertEquals(tree2.get_file_text('hello-id'), 'hello')
243
self.assertEquals(tree2.get_file_text('buongia-id'), 'new text')
258
self.assertEqual(tree2.get_file_text('hello'), b'hello')
259
self.assertEqual(tree2.get_file_text('buongia'), b'new text')
245
tree3 = b.repository.revision_tree('test@rev-3')
261
tree3 = b.repository.revision_tree(b'test@rev-3')
246
262
tree3.lock_read()
247
263
self.addCleanup(tree3.unlock)
248
264
self.assertFalse(tree3.has_filename('hello'))
249
self.assertEquals(tree3.get_file_text('buongia-id'), 'new text')
265
self.assertEqual(tree3.get_file_text('buongia'), b'new text')
251
267
def test_commit_rename(self):
252
268
"""Test commit of a revision where a file is renamed."""
253
269
tree = self.make_branch_and_tree('.')
255
271
self.build_tree(['hello'], line_endings='binary')
256
tree.add(['hello'], ['hello-id'])
257
tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
272
tree.add(['hello'], [b'hello-id'])
273
tree.commit(message='one', rev_id=b'test@rev-1', allow_pointless=False)
259
275
tree.rename_one('hello', 'fruity')
260
tree.commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
276
tree.commit(message='renamed', rev_id=b'test@rev-2',
277
allow_pointless=False)
262
eq = self.assertEquals
263
tree1 = b.repository.revision_tree('test@rev-1')
279
eq = self.assertEqual
280
tree1 = b.repository.revision_tree(b'test@rev-1')
264
281
tree1.lock_read()
265
282
self.addCleanup(tree1.unlock)
266
eq(tree1.id2path('hello-id'), 'hello')
267
eq(tree1.get_file_text('hello-id'), 'contents of hello\n')
283
eq(tree1.id2path(b'hello-id'), 'hello')
284
eq(tree1.get_file_text('hello'), b'contents of hello\n')
268
285
self.assertFalse(tree1.has_filename('fruity'))
269
286
self.check_tree_shape(tree1, ['hello'])
270
eq(tree1.get_file_revision('hello-id'), 'test@rev-1')
287
eq(tree1.get_file_revision('hello'), b'test@rev-1')
272
tree2 = b.repository.revision_tree('test@rev-2')
289
tree2 = b.repository.revision_tree(b'test@rev-2')
273
290
tree2.lock_read()
274
291
self.addCleanup(tree2.unlock)
275
eq(tree2.id2path('hello-id'), 'fruity')
276
eq(tree2.get_file_text('hello-id'), 'contents of hello\n')
292
eq(tree2.id2path(b'hello-id'), 'fruity')
293
eq(tree2.get_file_text('fruity'), b'contents of hello\n')
277
294
self.check_tree_shape(tree2, ['fruity'])
278
eq(tree2.get_file_revision('hello-id'), 'test@rev-2')
295
eq(tree2.get_file_revision('fruity'), b'test@rev-2')
280
297
def test_reused_rev_id(self):
281
298
"""Test that a revision id cannot be reused in a branch"""
282
299
wt = self.make_branch_and_tree('.')
284
wt.commit('initial', rev_id='test@rev-1', allow_pointless=True)
301
wt.commit('initial', rev_id=b'test@rev-1', allow_pointless=True)
285
302
self.assertRaises(Exception,
287
304
message='reused id',
305
rev_id=b'test@rev-1',
289
306
allow_pointless=True)
291
308
def test_commit_move(self):
292
309
"""Test commit of revisions with moved files and directories"""
293
eq = self.assertEquals
310
eq = self.assertEqual
294
311
wt = self.make_branch_and_tree('.')
297
314
self.build_tree(['hello', 'a/', 'b/'])
298
wt.add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
315
wt.add(['hello', 'a', 'b'], [b'hello-id', b'a-id', b'b-id'])
299
316
wt.commit('initial', rev_id=r1, allow_pointless=False)
300
317
wt.move(['hello'], 'a')
302
319
wt.commit('two', rev_id=r2, allow_pointless=False)
330
347
inv = b.repository.get_inventory(r4)
331
eq(inv['hello-id'].revision, r4)
332
eq(inv['a-id'].revision, r1)
333
eq(inv['b-id'].revision, r3)
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)
335
352
def test_removed_commit(self):
336
353
"""Commit with a removed file"""
337
354
wt = self.make_branch_and_tree('.')
339
with file('hello', 'w') as f: f.write('hello world')
340
wt.add(['hello'], ['hello-id'])
356
with open('hello', 'w') as f:
357
f.write('hello world')
358
wt.add(['hello'], [b'hello-id'])
341
359
wt.commit(message='add hello')
342
360
wt.remove('hello')
343
wt.commit('removed hello', rev_id='rev2')
361
wt.commit('removed hello', rev_id=b'rev2')
345
tree = b.repository.revision_tree('rev2')
346
self.assertFalse(tree.has_id('hello-id'))
363
tree = b.repository.revision_tree(b'rev2')
364
self.assertFalse(tree.has_filename('hello'))
348
366
def test_committed_ancestry(self):
349
367
"""Test commit appends revisions to ancestry."""
353
371
for i in range(4):
354
with file('hello', 'w') as f: f.write((str(i) * 4) + '\n')
372
with open('hello', 'w') as f:
373
f.write((str(i) * 4) + '\n')
356
wt.add(['hello'], ['hello-id'])
357
rev_id = 'test@rev-%d' % (i+1)
375
wt.add(['hello'], [b'hello-id'])
376
rev_id = b'test@rev-%d' % (i + 1)
358
377
rev_ids.append(rev_id)
359
wt.commit(message='rev %d' % (i+1),
378
wt.commit(message='rev %d' % (i + 1),
361
380
for i in range(4):
362
self.assertThat(rev_ids[:i+1],
363
MatchesAncestry(b.repository, rev_ids[i]))
381
self.assertThat(rev_ids[:i + 1],
382
MatchesAncestry(b.repository, rev_ids[i]))
365
384
def test_commit_new_subdir_child_selective(self):
366
385
wt = self.make_branch_and_tree('.')
368
387
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
369
388
wt.add(['dir', 'dir/file1', 'dir/file2'],
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)
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)
375
394
# FIXME: This should raise a KeyError I think, rbc20051006
376
self.assertRaises(BzrError, inv.__getitem__, 'file2id')
395
self.assertRaises(BzrError, inv.get_entry, b'file2id')
378
397
def test_strict_commit(self):
379
398
"""Try and commit with unknown files and strict = True, should fail."""
380
from bzrlib.errors import StrictCommitFailed
399
from ..errors import StrictCommitFailed
381
400
wt = self.make_branch_and_tree('.')
383
with file('hello', 'w') as f: f.write('hello world')
402
with open('hello', 'w') as f:
403
f.write('hello world')
385
with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
405
with open('goodbye', 'w') as f:
406
f.write('goodbye cruel world!')
386
407
self.assertRaises(StrictCommitFailed, wt.commit,
387
message='add hello but not goodbye', strict=True)
408
message='add hello but not goodbye', strict=True)
389
410
def test_strict_commit_without_unknowns(self):
390
411
"""Try and commit with no unknown files and strict = True,
392
413
wt = self.make_branch_and_tree('.')
394
with file('hello', 'w') as f: f.write('hello world')
415
with open('hello', 'w') as f:
416
f.write('hello world')
396
418
wt.commit(message='add hello', strict=True)
410
434
wt = self.make_branch_and_tree('.')
412
with file('hello', 'w') as f: f.write('hello world')
436
with open('hello', 'w') as f:
437
f.write('hello world')
414
439
wt.commit(message='add hello', strict=False)
416
441
def test_signed_commit(self):
418
import bzrlib.commit as commit
419
oldstrategy = bzrlib.gpg.GPGStrategy
443
import breezy.commit as commit
444
oldstrategy = breezy.gpg.GPGStrategy
420
445
wt = self.make_branch_and_tree('.')
421
446
branch = wt.branch
422
wt.commit("base", allow_pointless=True, rev_id='A')
423
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
447
wt.commit("base", allow_pointless=True, rev_id=b'A')
448
self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
425
from bzrlib.testament import Testament
450
from ..bzr.testament import Testament
426
451
# monkey patch gpg signing mechanism
427
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
428
conf = config.MemoryStack('''
429
gpg_signing_command=cat -
452
breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
453
conf = config.MemoryStack(b'''
430
454
create_signatures=always
432
456
commit.Commit(config_stack=conf).commit(
433
message="base", allow_pointless=True, rev_id='B',
457
message="base", allow_pointless=True, rev_id=b'B',
436
return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
461
return breezy.gpg.LoopbackGPGStrategy(None).sign(
462
text, breezy.gpg.MODE_CLEAR)
437
463
self.assertEqual(sign(Testament.from_revision(branch.repository,
438
'B').as_short_text()),
439
branch.repository.get_signature_text('B'))
464
b'B').as_short_text()),
465
branch.repository.get_signature_text(b'B'))
441
bzrlib.gpg.GPGStrategy = oldstrategy
467
breezy.gpg.GPGStrategy = oldstrategy
443
469
def test_commit_failed_signature(self):
445
import bzrlib.commit as commit
446
oldstrategy = bzrlib.gpg.GPGStrategy
471
import breezy.commit as commit
472
oldstrategy = breezy.gpg.GPGStrategy
447
473
wt = self.make_branch_and_tree('.')
448
474
branch = wt.branch
449
wt.commit("base", allow_pointless=True, rev_id='A')
450
self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
475
wt.commit("base", allow_pointless=True, rev_id=b'A')
476
self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
452
478
# monkey patch gpg signing mechanism
453
bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
454
conf = config.MemoryStack('''
455
gpg_signing_command=cat -
479
breezy.gpg.GPGStrategy = breezy.gpg.DisabledGPGStrategy
480
conf = config.MemoryStack(b'''
456
481
create_signatures=always
458
self.assertRaises(SigningFailed,
483
self.assertRaises(breezy.gpg.SigningFailed,
459
484
commit.Commit(config_stack=conf).commit,
461
486
allow_pointless=True,
464
489
branch = Branch.open(self.get_url('.'))
465
self.assertEqual(branch.last_revision(), 'A')
466
self.assertFalse(branch.repository.has_revision('B'))
490
self.assertEqual(branch.last_revision(), b'A')
491
self.assertFalse(branch.repository.has_revision(b'B'))
468
bzrlib.gpg.GPGStrategy = oldstrategy
493
breezy.gpg.GPGStrategy = oldstrategy
470
495
def test_commit_invokes_hooks(self):
471
import bzrlib.commit as commit
496
import breezy.commit as commit
472
497
wt = self.make_branch_and_tree('.')
473
498
branch = wt.branch
475
501
def called(branch, rev_id):
476
502
calls.append('called')
477
bzrlib.ahook = called
503
breezy.ahook = called
479
conf = config.MemoryStack('post_commit=bzrlib.ahook bzrlib.ahook')
505
conf = config.MemoryStack(b'post_commit=breezy.ahook breezy.ahook')
480
506
commit.Commit(config_stack=conf).commit(
481
message = "base", allow_pointless=True, rev_id='A',
507
message="base", allow_pointless=True, rev_id=b'A',
483
509
self.assertEqual(['called', 'called'], calls)
487
513
def test_commit_object_doesnt_set_nick(self):
488
514
# using the Commit object directly does not set the branch nick.
489
515
wt = self.make_branch_and_tree('.')
491
517
c.commit(working_tree=wt, message='empty tree', allow_pointless=True)
492
self.assertEquals(wt.branch.revno(), 1)
518
self.assertEqual(wt.branch.revno(), 1)
493
519
self.assertEqual({},
494
520
wt.branch.repository.get_revision(
495
wt.branch.last_revision()).properties)
521
wt.branch.last_revision()).properties)
497
523
def test_safe_master_lock(self):
498
524
os.mkdir('master')
516
539
bound_tree = self.make_branch_and_tree('bound')
517
540
bound_tree.branch.bind(master_branch)
519
self.build_tree_contents([('bound/content_file', 'initial contents\n')])
542
self.build_tree_contents(
543
[('bound/content_file', b'initial contents\n')])
520
544
bound_tree.add(['content_file'])
521
545
bound_tree.commit(message='woo!')
523
other_bzrdir = master_branch.bzrdir.sprout('other')
547
other_bzrdir = master_branch.controldir.sprout('other')
524
548
other_tree = other_bzrdir.open_workingtree()
526
550
# do a commit to the other branch changing the content file so
527
551
# that our commit after merging will have a merged revision in the
528
552
# content file history.
529
self.build_tree_contents([('other/content_file', 'change in other\n')])
553
self.build_tree_contents(
554
[('other/content_file', b'change in other\n')])
530
555
other_tree.commit('change in other')
532
557
# do a merge into the bound branch from other, and then change the
533
558
# content file locally to force a new revision (rather than using the
534
559
# revision from other). This forces extra processing in commit.
535
560
bound_tree.merge_from_branch(other_tree.branch)
536
self.build_tree_contents([('bound/content_file', 'change in bound\n')])
561
self.build_tree_contents(
562
[('bound/content_file', b'change in bound\n')])
538
564
# before #34959 was fixed, this failed with 'revision not present in
539
565
# weave' when trying to implicitly push from the bound branch to the master
637
661
tree = self.make_branch_and_tree('.')
638
662
self.build_tree(['a'])
640
tree.commit('added a', rev_id='a1')
664
tree.commit('added a', rev_id=b'a1')
642
rev = tree.branch.repository.get_revision('a1')
666
rev = tree.branch.repository.get_revision(b'a1')
643
667
timestamp = rev.timestamp
644
668
timestamp_1ms = round(timestamp, 3)
645
669
self.assertEqual(timestamp_1ms, timestamp)
647
def assertBasisTreeKind(self, kind, tree, file_id):
671
def assertBasisTreeKind(self, kind, tree, path):
648
672
basis = tree.basis_tree()
649
673
basis.lock_read()
651
self.assertEqual(kind, basis.kind(file_id))
675
self.assertEqual(kind, basis.kind(path))
679
def test_unsupported_symlink_commit(self):
680
self.requireFeature(SymlinkFeature)
681
tree = self.make_branch_and_tree('.')
682
self.build_tree(['hello'])
684
tree.commit('added hello', rev_id=b'hello_id')
685
os.symlink('hello', 'foo')
687
tree.commit('added foo', rev_id=b'foo_id')
689
trace.push_log_file(log)
690
os_symlink = getattr(os, 'symlink', None)
693
# At this point as bzr thinks symlinks are not supported
694
# we should get a warning about symlink foo and bzr should
695
# not think its removed.
697
self.build_tree(['world'])
699
tree.commit('added world', rev_id=b'world_id')
702
os.symlink = os_symlink
703
self.assertContainsRe(
705
b'Ignoring "foo" as symlinks are not '
706
b'supported on this filesystem\\.')
655
708
def test_commit_kind_changes(self):
656
709
self.requireFeature(SymlinkFeature)
657
710
tree = self.make_branch_and_tree('.')
658
711
os.symlink('target', 'name')
659
tree.add('name', 'a-file-id')
712
tree.add('name', b'a-file-id')
660
713
tree.commit('Added a symlink')
661
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
714
self.assertBasisTreeKind('symlink', tree, 'name')
663
716
os.unlink('name')
664
717
self.build_tree(['name'])
665
718
tree.commit('Changed symlink to file')
666
self.assertBasisTreeKind('file', tree, 'a-file-id')
719
self.assertBasisTreeKind('file', tree, 'name')
668
721
os.unlink('name')
669
722
os.symlink('target', 'name')
670
723
tree.commit('file to symlink')
671
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
724
self.assertBasisTreeKind('symlink', tree, 'name')
673
726
os.unlink('name')
675
728
tree.commit('symlink to directory')
676
self.assertBasisTreeKind('directory', tree, 'a-file-id')
729
self.assertBasisTreeKind('directory', tree, 'name')
679
732
os.symlink('target', 'name')
680
733
tree.commit('directory to symlink')
681
self.assertBasisTreeKind('symlink', tree, 'a-file-id')
734
self.assertBasisTreeKind('symlink', tree, 'name')
683
736
# prepare for directory <-> file tests
684
737
os.unlink('name')
686
739
tree.commit('symlink to directory')
687
self.assertBasisTreeKind('directory', tree, 'a-file-id')
740
self.assertBasisTreeKind('directory', tree, 'name')
690
743
self.build_tree(['name'])
691
744
tree.commit('Changed directory to file')
692
self.assertBasisTreeKind('file', tree, 'a-file-id')
745
self.assertBasisTreeKind('file', tree, 'name')
694
747
os.unlink('name')
696
749
tree.commit('file to directory')
697
self.assertBasisTreeKind('directory', tree, 'a-file-id')
750
self.assertBasisTreeKind('directory', tree, 'name')
699
752
def test_commit_unversioned_specified(self):
700
753
"""Commit should raise if specified files isn't in basis or worktree"""
813
867
def test_multiple_authors(self):
814
868
tree = self.make_branch_and_tree('foo')
815
869
rev_id = tree.commit('commit 1',
816
authors=['John Doe <jdoe@example.com>',
817
'Jane Rey <jrey@example.com>'])
870
authors=['John Doe <jdoe@example.com>',
871
'Jane Rey <jrey@example.com>'])
818
872
rev = tree.branch.repository.get_revision(rev_id)
819
873
self.assertEqual('John Doe <jdoe@example.com>\n'
820
'Jane Rey <jrey@example.com>', rev.properties['authors'])
874
'Jane Rey <jrey@example.com>', rev.properties['authors'])
821
875
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>")
830
877
def test_author_with_newline_rejected(self):
831
878
tree = self.make_branch_and_tree('foo')
832
879
self.assertRaises(AssertionError, tree.commit, 'commit 1',
833
authors=['John\nDoe <jdoe@example.com>'])
880
authors=['John\nDoe <jdoe@example.com>'])
835
882
def test_commit_with_checkout_and_branch_sharing_repo(self):
836
883
repo = self.make_repository('repo', shared=True)
837
884
# make_branch_and_tree ignores shared repos
838
885
branch = controldir.ControlDir.create_branch_convenience('repo/branch')
839
886
tree2 = branch.create_checkout('repo/tree2')
840
tree2.commit('message', rev_id='rev1')
841
self.assertTrue(tree2.branch.repository.has_revision('rev1'))
887
tree2.commit('message', rev_id=b'rev1')
888
self.assertTrue(tree2.branch.repository.has_revision(b'rev1'))
891
class FilterExcludedTests(TestCase):
893
def test_add_file_not_excluded(self):
896
'fid', (None, 'newpath'),
897
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
898
('file', 'file'), (True, True))]
899
self.assertEqual(changes, list(
900
filter_excluded(changes, ['otherpath'])))
902
def test_add_file_excluded(self):
905
'fid', (None, 'newpath'),
906
0, (False, False), ('pid', 'pid'), ('newpath', 'newpath'),
907
('file', 'file'), (True, True))]
908
self.assertEqual([], list(filter_excluded(changes, ['newpath'])))
910
def test_delete_file_excluded(self):
913
'fid', ('somepath', None),
914
0, (False, None), ('pid', None), ('newpath', None),
915
('file', None), (True, None))]
916
self.assertEqual([], list(filter_excluded(changes, ['somepath'])))
918
def test_move_from_or_to_excluded(self):
921
'fid', ('oldpath', 'newpath'),
922
0, (False, False), ('pid', 'pid'), ('oldpath', 'newpath'),
923
('file', 'file'), (True, True))]
924
self.assertEqual([], list(filter_excluded(changes, ['oldpath'])))
925
self.assertEqual([], list(filter_excluded(changes, ['newpath'])))