~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-07 17:02:44 UTC
  • mfrom: (4934.1.14 2.1.0rc1-set-mtime)
  • Revision ID: pqm@pqm.ubuntu.com-20100107170244-3cgdapvuokgf8l42
(jam,
        gz) (bug #488724) Set the mtime of files touched in a TreeTransform.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 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
343
343
        trunk = self.make_branch_and_tree('trunk')
344
344
 
345
345
        u1 = trunk.branch.create_checkout('u1')
346
 
        self.build_tree_contents([('u1/hosts', 'initial contents\n')])
 
346
        self.build_tree_contents([('u1/hosts', 'initial contents')])
347
347
        u1.add('hosts')
348
348
        self.run_bzr('commit -m add-hosts u1')
349
349
 
350
350
        u2 = trunk.branch.create_checkout('u2')
351
 
        self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
 
351
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
352
352
        self.run_bzr('commit -m checkin-from-u2 u2')
353
353
 
354
354
        # make an offline commits
355
 
        self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
 
355
        self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
356
356
        self.run_bzr('commit -m checkin-offline --local u1')
357
357
 
358
358
        # now try to pull in online work from u2, and then commit our offline
359
359
        # work as a merge
360
360
        # retcode 1 as we expect a text conflict
361
361
        self.run_bzr('update u1', retcode=1)
362
 
        self.assertFileEqual('''\
363
 
<<<<<<< TREE
364
 
first offline change in u1
365
 
=======
366
 
altered in u2
367
 
>>>>>>> MERGE-SOURCE
368
 
''',
369
 
                             'u1/hosts')
370
 
 
371
362
        self.run_bzr('resolved u1/hosts')
372
363
        # add a text change here to represent resolving the merge conflicts in
373
364
        # favour of a new version of the file not identical to either the u1
675
666
        self.assertContainsRe(err,
676
667
            r'^bzr: ERROR: Cannot lock.*readonly transport')
677
668
 
678
 
    def setup_editor(self):
 
669
    def test_commit_hook_template(self):
679
670
        # Test that commit template hooks work
 
671
        def restoreDefaults():
 
672
            msgeditor.hooks['commit_message_template'] = []
 
673
            osutils.set_or_unset_env('BZR_EDITOR', default_editor)
680
674
        if sys.platform == "win32":
681
675
            f = file('fed.bat', 'w')
682
676
            f.write('@rem dummy fed')
683
677
            f.close()
684
 
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
678
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
685
679
        else:
686
680
            f = file('fed.sh', 'wb')
687
681
            f.write('#!/bin/sh\n')
688
682
            f.close()
689
683
            os.chmod('fed.sh', 0755)
690
 
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
691
 
 
692
 
    def setup_commit_with_template(self):
693
 
        self.setup_editor()
 
684
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
685
        self.addCleanup(restoreDefaults)
694
686
        msgeditor.hooks.install_named_hook("commit_message_template",
695
687
                lambda commit_obj, msg: "save me some typing\n", None)
696
688
        tree = self.make_branch_and_tree('tree')
697
689
        self.build_tree(['tree/hello.txt'])
698
690
        tree.add('hello.txt')
699
 
        return tree
700
 
 
701
 
    def test_commit_hook_template_accepted(self):
702
 
        tree = self.setup_commit_with_template()
703
 
        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
 
691
        out, err = self.run_bzr("commit tree/hello.txt")
704
692
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
705
693
        self.assertEqual('save me some typing\n', last_rev.message)
706
 
 
707
 
    def test_commit_hook_template_rejected(self):
708
 
        tree = self.setup_commit_with_template()
709
 
        expected = tree.last_revision()
710
 
        out, err = self.run_bzr_error(["empty commit message"],
711
 
            "commit tree/hello.txt", stdin="n\n")
712
 
        self.assertEqual(expected, tree.last_revision())