~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

  • Committer: Martin Pool
  • Date: 2006-08-10 01:16:16 UTC
  • mto: (1904.1.2 0.9)
  • mto: This revision was merged to the branch mainline in revision 1913.
  • Revision ID: mbp@sourcefrog.net-20060810011616-d74881eba696e746
compare_trees is deprecated in 0.9 not 0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
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
18
18
import os
19
19
 
20
20
import bzrlib
21
 
from bzrlib import (
22
 
    errors,
23
 
    lockdir,
24
 
    )
 
21
from bzrlib.tests import TestCaseWithTransport
25
22
from bzrlib.branch import Branch
26
23
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
 
24
from bzrlib.workingtree import WorkingTree
27
25
from bzrlib.commit import Commit, NullCommitReporter
28
26
from bzrlib.config import BranchConfig
29
27
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed, 
30
28
                           LockContention)
31
 
from bzrlib.tests import TestCaseWithTransport
32
 
from bzrlib.workingtree import WorkingTree
33
29
 
34
30
 
35
31
# TODO: Test commit with some added, and added-but-missing files
411
407
        bound = master.sprout('bound')
412
408
        wt = bound.open_workingtree()
413
409
        wt.branch.set_bound_location(os.path.realpath('master'))
414
 
 
415
 
        orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
416
410
        master_branch.lock_write()
417
411
        try:
418
 
            lockdir._DEFAULT_TIMEOUT_SECONDS = 1
419
412
            self.assertRaises(LockContention, wt.commit, 'silly')
420
413
        finally:
421
 
            lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
422
414
            master_branch.unlock()
423
415
 
424
416
    def test_commit_bound_merge(self):
444
436
        # do a merge into the bound branch from other, and then change the
445
437
        # content file locally to force a new revision (rather than using the
446
438
        # revision from other). This forces extra processing in commit.
447
 
        bound_tree.merge_from_branch(other_tree.branch)
 
439
        self.merge(other_tree.branch, bound_tree)
448
440
        self.build_tree_contents([('bound/content_file', 'change in bound\n')])
449
441
 
450
442
        # before #34959 was fixed, this failed with 'revision not present in
498
490
            other_tree.commit('modify all sample files and dirs.')
499
491
        finally:
500
492
            other_tree.unlock()
501
 
        this_tree.merge_from_branch(other_tree.branch)
 
493
        self.merge(other_tree.branch, this_tree)
502
494
        reporter = CapturingReporter()
503
495
        this_tree.commit('do the commit', reporter=reporter)
504
496
        self.assertEqual([
505
 
            ('change', 'unchanged', ''),
506
497
            ('change', 'unchanged', 'dirtoleave'),
507
498
            ('change', 'unchanged', 'filetoleave'),
508
499
            ('change', 'modified', 'filetomodify'),
524
515
        tree.add(['a', 'b'])
525
516
        tree.commit('added a, b')
526
517
        tree.remove(['a', 'b'])
527
 
        tree.commit('removed a', specific_files='a')
 
518
        Commit().commit(message='removed a', working_tree=tree, 
 
519
                        specific_files='a')
528
520
        basis = tree.basis_tree().inventory
529
521
        self.assertIs(None, basis.path2id('a'))
530
522
        self.assertFalse(basis.path2id('b') is None)
551
543
        timestamp = rev.timestamp
552
544
        timestamp_1ms = round(timestamp, 3)
553
545
        self.assertEqual(timestamp_1ms, timestamp)
554
 
 
555
 
    def test_commit_unversioned_specified(self):
556
 
        """Commit should raise if specified files isn't in basis or worktree"""
557
 
        tree = self.make_branch_and_tree('.')
558
 
        self.assertRaises(errors.PathsNotVersionedError, tree.commit, 
559
 
                          'message', specific_files=['bogus'])
560
 
 
561
 
    class Callback(object):
562
 
        
563
 
        def __init__(self, message, testcase):
564
 
            self.called = False
565
 
            self.message = message
566
 
            self.testcase = testcase
567
 
 
568
 
        def __call__(self, commit_obj):
569
 
            self.called = True
570
 
            self.testcase.assertTrue(isinstance(commit_obj, Commit))
571
 
            return self.message
572
 
 
573
 
    def test_commit_callback(self):
574
 
        """Commit should invoke a callback to get the message"""
575
 
 
576
 
        tree = self.make_branch_and_tree('.')
577
 
        try:
578
 
            tree.commit()
579
 
        except Exception, e:
580
 
            self.assertTrue(isinstance(e, BzrError))
581
 
            self.assertEqual('The message or message_callback keyword'
582
 
                             ' parameter is required for commit().', str(e))
583
 
        else:
584
 
            self.fail('exception not raised')
585
 
        cb = self.Callback(u'commit 1', self)
586
 
        tree.commit(message_callback=cb)
587
 
        self.assertTrue(cb.called)
588
 
        repository = tree.branch.repository
589
 
        message = repository.get_revision(tree.last_revision()).message
590
 
        self.assertEqual('commit 1', message)
591
 
 
592
 
    def test_no_callback_pointless(self):
593
 
        """Callback should not be invoked for pointless commit"""
594
 
        tree = self.make_branch_and_tree('.')
595
 
        cb = self.Callback(u'commit 2', self)
596
 
        self.assertRaises(PointlessCommit, tree.commit, message_callback=cb, 
597
 
                          allow_pointless=False)
598
 
        self.assertFalse(cb.called)
599
 
 
600
 
    def test_no_callback_netfailure(self):
601
 
        """Callback should not be invoked if connectivity fails"""
602
 
        tree = self.make_branch_and_tree('.')
603
 
        cb = self.Callback(u'commit 2', self)
604
 
        repository = tree.branch.repository
605
 
        # simulate network failure
606
 
        def raise_(self, arg, arg2):
607
 
            raise errors.NoSuchFile('foo')
608
 
        repository.add_inventory = raise_
609
 
        self.assertRaises(errors.NoSuchFile, tree.commit, message_callback=cb)
610
 
        self.assertFalse(cb.called)