~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2009-03-24 05:21:02 UTC
  • mfrom: (4192 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20090324052102-8kk087b32tep3d9h
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import sys
22
22
 
23
 
import bzrlib
24
23
from bzrlib import (
25
24
    osutils,
26
25
    ignores,
 
26
    msgeditor,
27
27
    osutils,
28
28
    )
29
29
from bzrlib.bzrdir import BzrDir
248
248
        # LANG env variable has no effect on Windows
249
249
        # but some characters anyway cannot be represented
250
250
        # in default user encoding
251
 
        char = probe_bad_non_ascii(bzrlib.user_encoding)
 
251
        char = probe_bad_non_ascii(osutils.get_user_encoding())
252
252
        if char is None:
253
253
            raise TestSkipped('Cannot find suitable non-ascii character'
254
 
                'for user_encoding (%s)' % bzrlib.user_encoding)
 
254
                'for user_encoding (%s)' % osutils.get_user_encoding())
255
255
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
256
256
                                          retcode=1,
257
257
                                          env_changes={'LANG': 'C'})
302
302
    def test_commit_a_text_merge_in_a_checkout(self):
303
303
        # checkouts perform multiple actions in a transaction across bond
304
304
        # branches and their master, and have been observed to fail in the
305
 
        # past. This is a user story reported to fail in bug #43959 where 
 
305
        # past. This is a user story reported to fail in bug #43959 where
306
306
        # a merge done in a checkout (using the update command) failed to
307
307
        # commit correctly.
308
308
        trunk = self.make_branch_and_tree('trunk')
331
331
        self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
332
332
        self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
333
333
 
 
334
    def test_commit_exclude_excludes_modified_files(self):
 
335
        """Commit -x foo should ignore changes to foo."""
 
336
        tree = self.make_branch_and_tree('.')
 
337
        self.build_tree(['a', 'b', 'c'])
 
338
        tree.smart_add(['.'])
 
339
        out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
 
340
        self.assertFalse('added b' in out)
 
341
        self.assertFalse('added b' in err)
 
342
        # If b was excluded it will still be 'added' in status.
 
343
        out, err = self.run_bzr(['added'])
 
344
        self.assertEqual('b\n', out)
 
345
        self.assertEqual('', err)
 
346
 
 
347
    def test_commit_exclude_twice_uses_both_rules(self):
 
348
        """Commit -x foo -x bar should ignore changes to foo and bar."""
 
349
        tree = self.make_branch_and_tree('.')
 
350
        self.build_tree(['a', 'b', 'c'])
 
351
        tree.smart_add(['.'])
 
352
        out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
 
353
        self.assertFalse('added b' in out)
 
354
        self.assertFalse('added c' in out)
 
355
        self.assertFalse('added b' in err)
 
356
        self.assertFalse('added c' in err)
 
357
        # If b was excluded it will still be 'added' in status.
 
358
        out, err = self.run_bzr(['added'])
 
359
        self.assertTrue('b\n' in out)
 
360
        self.assertTrue('c\n' in out)
 
361
        self.assertEqual('', err)
 
362
 
334
363
    def test_commit_respects_spec_for_removals(self):
335
364
        """Commit with a file spec should only commit removals that match"""
336
365
        t = self.make_branch_and_tree('.')
488
517
        self.build_tree(['tree/hello.txt'])
489
518
        tree.add('hello.txt')
490
519
        self.run_bzr_error(
491
 
            ["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
 
520
            ["Did not understand bug identifier orange: Must be an integer. "
 
521
             "See \"bzr help bugs\" for more information on this feature.\n"
 
522
             "Commit refused."],
492
523
            'commit -m add-b --fixes=lp:orange',
493
524
            working_dir='tree')
494
525
 
498
529
        self.build_tree(['tree/hello.txt'])
499
530
        tree.add('hello.txt')
500
531
        self.run_bzr_error(
501
 
            [r"Invalid bug orange. Must be in the form of 'tag:id'\. "
 
532
            [r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
 
533
             r"See \"bzr help bugs\" for more information on this feature.\n"
502
534
             r"Commit refused\."],
503
535
            'commit -m add-b --fixes=orange',
504
536
            working_dir='tree')
525
557
                     "tree/hello.txt"])
526
558
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
527
559
        properties = last_rev.properties
528
 
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['author'])
 
560
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
529
561
 
530
562
    def test_author_no_email(self):
531
563
        """Author's name without an email address is allowed, too."""
536
568
                                "tree/hello.txt")
537
569
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
538
570
        properties = last_rev.properties
539
 
        self.assertEqual('John Doe', properties['author'])
 
571
        self.assertEqual('John Doe', properties['authors'])
 
572
 
 
573
    def test_multiple_authors(self):
 
574
        """Multiple authors can be specyfied, and all are stored."""
 
575
        tree = self.make_branch_and_tree('tree')
 
576
        self.build_tree(['tree/hello.txt'])
 
577
        tree.add('hello.txt')
 
578
        out, err = self.run_bzr("commit -m hello --author='John Doe' "
 
579
                                "--author='Jane Rey' tree/hello.txt")
 
580
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
581
        properties = last_rev.properties
 
582
        self.assertEqual('John Doe\nJane Rey', properties['authors'])
540
583
 
541
584
    def test_partial_commit_with_renames_in_tree(self):
542
585
        # this test illustrates bug #140419
567
610
            retcode=3)
568
611
        self.assertContainsRe(err,
569
612
            r'^bzr: ERROR: Cannot lock.*readonly transport')
 
613
 
 
614
    def test_commit_hook_template(self):
 
615
        # Test that commit template hooks work
 
616
        def restoreDefaults():
 
617
            msgeditor.hooks['commit_message_template'] = []
 
618
            osutils.set_or_unset_env('BZR_EDITOR', default_editor)
 
619
        if sys.platform == "win32":
 
620
            f = file('fed.bat', 'w')
 
621
            f.write('@rem dummy fed')
 
622
            f.close()
 
623
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
624
        else:
 
625
            f = file('fed.sh', 'wb')
 
626
            f.write('#!/bin/sh\n')
 
627
            f.close()
 
628
            os.chmod('fed.sh', 0755)
 
629
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
630
        self.addCleanup(restoreDefaults)
 
631
        msgeditor.hooks.install_named_hook("commit_message_template",
 
632
                lambda commit_obj, msg: "save me some typing\n", None)
 
633
        tree = self.make_branch_and_tree('tree')
 
634
        self.build_tree(['tree/hello.txt'])
 
635
        tree.add('hello.txt')
 
636
        out, err = self.run_bzr("commit tree/hello.txt")
 
637
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
638
        self.assertEqual('save me some typing\n', last_rev.message)