/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

Tidy imports, skip test if paramiko isn't installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
2
 
 
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
22
from bzrlib.branch import Branch
23
23
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
24
24
from bzrlib.workingtree import WorkingTree
25
 
from bzrlib.commit import Commit
 
25
from bzrlib.commit import Commit, NullCommitReporter
26
26
from bzrlib.config import BranchConfig
27
27
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed, 
28
28
                           LockContention)
45
45
        return "bzrlib.ahook bzrlib.ahook"
46
46
 
47
47
 
 
48
class CapturingReporter(NullCommitReporter):
 
49
    """This reporter captures the calls made to it for evaluation later."""
 
50
 
 
51
    def __init__(self):
 
52
        # a list of the calls this received
 
53
        self.calls = []
 
54
 
 
55
    def snapshot_change(self, change, path):
 
56
        self.calls.append(('change', change, path))
 
57
 
 
58
    def deleted(self, file_id):
 
59
        self.calls.append(('deleted', file_id))
 
60
 
 
61
    def missing(self, path):
 
62
        self.calls.append(('missing', path))
 
63
 
 
64
    def renamed(self, change, old_path, new_path):
 
65
        self.calls.append(('renamed', change, old_path, new_path))
 
66
 
 
67
 
48
68
class TestCommit(TestCaseWithTransport):
49
69
 
50
70
    def test_simple_commit(self):
392
412
            self.assertRaises(LockContention, wt.commit, 'silly')
393
413
        finally:
394
414
            master_branch.unlock()
 
415
 
 
416
    def test_commit_bound_merge(self):
 
417
        # see bug #43959; commit of a merge in a bound branch fails to push
 
418
        # the new commit into the master
 
419
        master_branch = self.make_branch('master')
 
420
        bound_tree = self.make_branch_and_tree('bound')
 
421
        bound_tree.branch.bind(master_branch)
 
422
 
 
423
        self.build_tree_contents([('bound/content_file', 'initial contents\n')])
 
424
        bound_tree.add(['content_file'])
 
425
        bound_tree.commit(message='woo!')
 
426
 
 
427
        other_bzrdir = master_branch.bzrdir.sprout('other')
 
428
        other_tree = other_bzrdir.open_workingtree()
 
429
 
 
430
        # do a commit to the the other branch changing the content file so
 
431
        # that our commit after merging will have a merged revision in the
 
432
        # content file history.
 
433
        self.build_tree_contents([('other/content_file', 'change in other\n')])
 
434
        other_tree.commit('change in other')
 
435
 
 
436
        # do a merge into the bound branch from other, and then change the
 
437
        # content file locally to force a new revision (rather than using the
 
438
        # revision from other). This forces extra processing in commit.
 
439
        bound_tree.merge_from_branch(other_tree.branch)
 
440
        self.build_tree_contents([('bound/content_file', 'change in bound\n')])
 
441
 
 
442
        # before #34959 was fixed, this failed with 'revision not present in
 
443
        # weave' when trying to implicitly push from the bound branch to the master
 
444
        bound_tree.commit(message='commit of merge in bound tree')
 
445
 
 
446
    def test_commit_reporting_after_merge(self):
 
447
        # when doing a commit of a merge, the reporter needs to still 
 
448
        # be called for each item that is added/removed/deleted.
 
449
        this_tree = self.make_branch_and_tree('this')
 
450
        # we need a bunch of files and dirs, to perform one action on each.
 
451
        self.build_tree([
 
452
            'this/dirtorename/',
 
453
            'this/dirtoreparent/',
 
454
            'this/dirtoleave/',
 
455
            'this/dirtoremove/',
 
456
            'this/filetoreparent',
 
457
            'this/filetorename',
 
458
            'this/filetomodify',
 
459
            'this/filetoremove',
 
460
            'this/filetoleave']
 
461
            )
 
462
        this_tree.add([
 
463
            'dirtorename',
 
464
            'dirtoreparent',
 
465
            'dirtoleave',
 
466
            'dirtoremove',
 
467
            'filetoreparent',
 
468
            'filetorename',
 
469
            'filetomodify',
 
470
            'filetoremove',
 
471
            'filetoleave']
 
472
            )
 
473
        this_tree.commit('create_files')
 
474
        other_dir = this_tree.bzrdir.sprout('other')
 
475
        other_tree = other_dir.open_workingtree()
 
476
        other_tree.lock_write()
 
477
        # perform the needed actions on the files and dirs.
 
478
        try:
 
479
            other_tree.rename_one('dirtorename', 'renameddir')
 
480
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
 
481
            other_tree.rename_one('filetorename', 'renamedfile')
 
482
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
483
            other_tree.remove(['dirtoremove', 'filetoremove'])
 
484
            self.build_tree_contents([
 
485
                ('other/newdir/', ),
 
486
                ('other/filetomodify', 'new content'),
 
487
                ('other/newfile', 'new file content')])
 
488
            other_tree.add('newfile')
 
489
            other_tree.add('newdir/')
 
490
            other_tree.commit('modify all sample files and dirs.')
 
491
        finally:
 
492
            other_tree.unlock()
 
493
        this_tree.merge_from_branch(other_tree.branch)
 
494
        reporter = CapturingReporter()
 
495
        this_tree.commit('do the commit', reporter=reporter)
 
496
        self.assertEqual([
 
497
            ('change', 'unchanged', ''),
 
498
            ('change', 'unchanged', 'dirtoleave'),
 
499
            ('change', 'unchanged', 'filetoleave'),
 
500
            ('change', 'modified', 'filetomodify'),
 
501
            ('change', 'added', 'newdir'),
 
502
            ('change', 'added', 'newfile'),
 
503
            ('renamed', 'renamed', 'dirtorename', 'renameddir'),
 
504
            ('renamed', 'renamed', 'dirtoreparent', 'renameddir/reparenteddir'),
 
505
            ('renamed', 'renamed', 'filetoreparent', 'renameddir/reparentedfile'),
 
506
            ('renamed', 'renamed', 'filetorename', 'renamedfile'),
 
507
            ('deleted', 'dirtoremove'),
 
508
            ('deleted', 'filetoremove'),
 
509
            ],
 
510
            reporter.calls)
 
511
 
 
512
    def test_commit_removals_respects_filespec(self):
 
513
        """Commit respects the specified_files for removals."""
 
514
        tree = self.make_branch_and_tree('.')
 
515
        self.build_tree(['a', 'b'])
 
516
        tree.add(['a', 'b'])
 
517
        tree.commit('added a, b')
 
518
        tree.remove(['a', 'b'])
 
519
        tree.commit('removed a', specific_files='a')
 
520
        basis = tree.basis_tree().inventory
 
521
        self.assertIs(None, basis.path2id('a'))
 
522
        self.assertFalse(basis.path2id('b') is None)
 
523
 
 
524
    def test_commit_saves_1ms_timestamp(self):
 
525
        """Passing in a timestamp is saved with 1ms resolution"""
 
526
        tree = self.make_branch_and_tree('.')
 
527
        self.build_tree(['a'])
 
528
        tree.add('a')
 
529
        tree.commit('added a', timestamp=1153248633.4186721, timezone=0,
 
530
                    rev_id='a1')
 
531
 
 
532
        rev = tree.branch.repository.get_revision('a1')
 
533
        self.assertEqual(1153248633.419, rev.timestamp)
 
534
 
 
535
    def test_commit_has_1ms_resolution(self):
 
536
        """Allowing commit to generate the timestamp also has 1ms resolution"""
 
537
        tree = self.make_branch_and_tree('.')
 
538
        self.build_tree(['a'])
 
539
        tree.add('a')
 
540
        tree.commit('added a', rev_id='a1')
 
541
 
 
542
        rev = tree.branch.repository.get_revision('a1')
 
543
        timestamp = rev.timestamp
 
544
        timestamp_1ms = round(timestamp, 3)
 
545
        self.assertEqual(timestamp_1ms, timestamp)