~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_commit.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
from cStringIO import StringIO
19
19
import os
30
30
    uncommit,
31
31
    workingtree,
32
32
    )
33
 
from bzrlib.errors import (NotBranchError, NotVersionedError, 
 
33
from bzrlib.errors import (NotBranchError, NotVersionedError,
34
34
                           UnsupportedOperation)
35
35
from bzrlib.osutils import pathjoin, getcwd
36
36
from bzrlib.tests import TestCase
63
63
 
64
64
    def progress_bar(self):
65
65
        return self
66
 
    
 
66
 
67
67
    def nested_progress_bar(self):
68
68
        self.depth += 1
69
69
        return self
255
255
        self.assertNotEqual(None, committed_id)
256
256
 
257
257
    def test_commit_local_unbound(self):
258
 
        # using the library api to do a local commit on unbound branches is 
 
258
        # using the library api to do a local commit on unbound branches is
259
259
        # also an error
260
260
        tree = self.make_branch_and_tree('tree')
261
261
        self.assertRaises(errors.LocalRequiresBoundBranch,
299
299
                          bzrdir.BzrDir.open,
300
300
                          'master')
301
301
        tree.commit('foo', rev_id='foo', local=True)
302
 
 
 
302
 
303
303
    def test_local_commit_does_not_push_to_master(self):
304
304
        # a --local commit does not require access to the master branch
305
305
        # at all, or even for it to exist.
444
444
            basis.get_reference_revision(basis.path2id('subtree')))
445
445
        # the outer tree must have have changed too.
446
446
        self.assertNotEqual(None, rev_id)
447
 
        
 
447
 
448
448
    def test_nested_commit_second_commit_detects_changes(self):
449
449
        """Commit with a nested tree picks up the correct child revid."""
450
450
        tree = self.make_branch_and_tree('.')
456
456
        self.build_tree(['subtree/file'])
457
457
        subtree.add(['file'], ['file-id'])
458
458
        rev_id = tree.commit('added reference', allow_pointless=False)
 
459
        tree.get_reference_revision(tree.path2id('subtree'))
459
460
        child_revid = subtree.last_revision()
460
461
        # now change the child tree
461
462
        self.build_tree_contents([('subtree/file', 'new-content')])
494
495
 
495
496
 
496
497
class TestCommitProgress(TestCaseWithWorkingTree):
497
 
    
 
498
 
498
499
    def restoreDefaults(self):
499
500
        ui.ui_factory = self.old_ui_factory
500
501
 
501
502
    def test_commit_progress_steps(self):
502
 
        # during commit we one progress update for every entry in the 
 
503
        # during commit we one progress update for every entry in the
503
504
        # inventory, and then one for the inventory, and one for the
504
505
        # inventory, and one for the revision insertions.
505
 
        # first we need a test commit to do. Lets setup a branch with 
 
506
        # first we need a test commit to do. Lets setup a branch with
506
507
        # 3 files, and alter one in a selected-file commit. This exercises
507
 
        # a number of cases quickly. We should also test things like 
 
508
        # a number of cases quickly. We should also test things like
508
509
        # selective commits which excludes newly added files.
509
510
        tree = self.make_branch_and_tree('.')
510
511
        self.build_tree(['a', 'b', 'c'])
513
514
        f = file('b', 'wt')
514
515
        f.write('new content')
515
516
        f.close()
516
 
        # set a progress bar that captures the calls so we can see what is 
 
517
        # set a progress bar that captures the calls so we can see what is
517
518
        # emitted
518
519
        self.old_ui_factory = ui.ui_factory
519
520
        self.addCleanup(self.restoreDefaults)
525
526
        tree.commit('second post', specific_files=['b'])
526
527
        # 5 steps, the first of which is reported 2 times, once per dir
527
528
        self.assertEqual(
528
 
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
529
 
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
 
529
            [('update', 1, 5, 'Collecting changes [0] - Stage'),
 
530
             ('update', 1, 5, 'Collecting changes [1] - Stage'),
530
531
             ('update', 2, 5, 'Saving data locally - Stage'),
531
532
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
532
533
             ('update', 4, 5, 'Updating the working tree - Stage'),
536
537
 
537
538
    def test_commit_progress_shows_post_hook_names(self):
538
539
        tree = self.make_branch_and_tree('.')
539
 
        # set a progress bar that captures the calls so we can see what is 
 
540
        # set a progress bar that captures the calls so we can see what is
540
541
        # emitted
541
542
        self.old_ui_factory = ui.ui_factory
542
543
        self.addCleanup(self.restoreDefaults)
548
549
                                               'hook name')
549
550
        tree.commit('first post')
550
551
        self.assertEqual(
551
 
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
552
 
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
 
552
            [('update', 1, 5, 'Collecting changes [0] - Stage'),
 
553
             ('update', 1, 5, 'Collecting changes [1] - Stage'),
553
554
             ('update', 2, 5, 'Saving data locally - Stage'),
554
555
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
555
556
             ('update', 4, 5, 'Updating the working tree - Stage'),
561
562
 
562
563
    def test_commit_progress_shows_pre_hook_names(self):
563
564
        tree = self.make_branch_and_tree('.')
564
 
        # set a progress bar that captures the calls so we can see what is 
 
565
        # set a progress bar that captures the calls so we can see what is
565
566
        # emitted
566
567
        self.old_ui_factory = ui.ui_factory
567
568
        self.addCleanup(self.restoreDefaults)
573
574
                                               'hook name')
574
575
        tree.commit('first post')
575
576
        self.assertEqual(
576
 
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
577
 
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
 
577
            [('update', 1, 5, 'Collecting changes [0] - Stage'),
 
578
             ('update', 1, 5, 'Collecting changes [1] - Stage'),
578
579
             ('update', 2, 5, 'Saving data locally - Stage'),
579
580
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
580
581
             ('update', 3, 5, 'Running pre_commit hooks [hook name] - Stage'),
585
586
           )
586
587
 
587
588
    def test_start_commit_hook(self):
588
 
        """Make sure a start commit hook can modify the tree that is 
 
589
        """Make sure a start commit hook can modify the tree that is
589
590
        committed."""
590
591
        def start_commit_hook_adds_file(tree):
591
592
            open(tree.abspath("newfile"), 'w').write("data")