Rev 3828: (Jelmer) Add simple commit message template hook. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Nov 11 02:39:47 GMT 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3828
revision-id: pqm at pqm.ubuntu.com-20081111023942-ir0du8iel76giykh
parent: pqm at pqm.ubuntu.com-20081111015238-n9zq9dpfbzjhw0ml
parent: jelmer at samba.org-20081111004606-pzi7dybhqdymlsbz
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-11-11 02:39:42 +0000
message:
  (Jelmer) Add simple commit message template hook.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
  bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
  bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
  bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
    ------------------------------------------------------------
    revno: 3825.2.3
    revision-id: jelmer at samba.org-20081111004606-pzi7dybhqdymlsbz
    parent: jelmer at samba.org-20081111001303-fwe3p0hwny1j5xnq
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: hook
    timestamp: Tue 2008-11-11 01:46:06 +0100
    message:
      Move NEWS entry to latest version, update versions to 1.10.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
      bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
    ------------------------------------------------------------
    revno: 3825.2.2
    revision-id: jelmer at samba.org-20081111001303-fwe3p0hwny1j5xnq
    parent: jelmer at samba.org-20081110224221-zc0laazvmciyi3tb
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: hook
    timestamp: Tue 2008-11-11 01:13:03 +0100
    message:
      Add blackbox test for commit hook templates.
    modified:
      bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
    ------------------------------------------------------------
    revno: 3825.2.1
    revision-id: jelmer at samba.org-20081110224221-zc0laazvmciyi3tb
    parent: pqm at pqm.ubuntu.com-20081107225426-gezbao014attrca8
    parent: jelmer at samba.org-20080906035445-e4a4lci55jo7uu8p
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: hook
    timestamp: Mon 2008-11-10 23:42:21 +0100
    message:
      Merge commit hook template patch.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
      bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
      bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
    ------------------------------------------------------------
    revno: 3642.2.4
    revision-id: jelmer at samba.org-20080906035445-e4a4lci55jo7uu8p
    parent: jelmer at samba.org-20080906034320-px4f5405i1mkhsm4
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: commit-message-template-hook
    timestamp: Sat 2008-09-06 05:54:45 +0200
    message:
      review feedback from John.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
      bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
    ------------------------------------------------------------
    revno: 3642.2.3
    revision-id: jelmer at samba.org-20080906034320-px4f5405i1mkhsm4
    parent: jelmer at samba.org-20080821165821-r5vaoznc96k0kd18
    parent: pqm at pqm.ubuntu.com-20080905212548-ig8wqqpv4vb8b2v4
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: commit-message-template-hook
    timestamp: Sat 2008-09-06 05:43:20 +0200
    message:
      Merge bzr.dev.
    added:
      bzrlib/_btree_serializer_c.pyx _parse_btree_c.pyx-20080703034413-3q25bklkenti3p8p-2
      bzrlib/_btree_serializer_py.py _parse_btree_py.py-20080703034413-3q25bklkenti3p8p-3
      bzrlib/_readdir_py.py          readdir.py-20060609152855-rm6v321vuaqyh9tu-3
      bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
      bzrlib/btree_index.py          index.py-20080624222253-p0x5f92uyh5hw734-7
      bzrlib/chunk_writer.py         chunk_writer.py-20080630234519-6ggn4id17nipovny-1
      bzrlib/readdir.h               readdir.h-20060609152855-rm6v321vuaqyh9tu-2
      bzrlib/tests/test_btree_index.py test_index.py-20080624222253-p0x5f92uyh5hw734-13
      bzrlib/tests/test_chunk_writer.py test_chunk_writer.py-20080630234519-6ggn4id17nipovny-2
      bzrlib/tests/test_transport_log.py test_transport_log.p-20080902041816-vh8x5yt5nvdzvew3-3
      bzrlib/transport/ftp/          ftp-20080611185801-3vm145h8dmnfgh25-1
      bzrlib/transport/ftp/_gssapi.py _gssapi.py-20080611190840-7ejrtp884bk5eu72-2
      bzrlib/transport/log.py        log.py-20080902041816-vh8x5yt5nvdzvew3-5
      doc/developers/overview.txt    overview.txt-20080904022501-ww2ggomrs5elxfm0-1
      tools/packaging/               packaging-20080825202834-3j433iaawnt72wqa-1
      tools/packaging/build-packages.sh buildpackages.sh-20080821102059-fzlodktas65qmo1k-1
      tools/packaging/update-changelogs.sh updatechangelogs.sh-20080821102059-fzlodktas65qmo1k-2
      tools/packaging/update-packaging-branches.sh updatepackagingbranc-20080825210254-6is8ciit1yzyd3a2-1
    renamed:
      bzrlib/transport/ftp.py => bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
      doc/en/developer-guide/testing.txt => doc/developers/testing.txt testing.txt-20080812140359-i70zzh6v2z7grqex-1
    modified:
      .bzrignore                     bzrignore-20050311232317-81f7b71efa2db11a
      Makefile                       Makefile-20050805140406-d96e3498bb61c5bb
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/_dirstate_helpers_c.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
      bzrlib/_dirstate_helpers_py.py _dirstate_helpers_py-20070710145033-90nz6cqglsk150jy-1
      bzrlib/_patiencediff_c.c       _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
      bzrlib/atomicfile.py           atomicfile.py-20050509044450-dbd24e6c564f7c66
      bzrlib/benchmarks/bench_osutils.py bench_osutils.py-20060608153714-apso8cyz1bu2z1ig-1
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bundle/bundle_data.py   read_changeset.py-20050619171944-c0d95aa685537640
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
      bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
      bzrlib/lockdir.py              lockdir.py-20060220222025-98258adf27fbdda3
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/memorytree.py           memorytree.py-20060906023413-4wlkalbdpsxi2r4y-1
      bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
      bzrlib/missing.py              missing.py-20050812153334-097f7097e2a8bcd1
      bzrlib/option.py               option.py-20051014052914-661fb36e76e7362f
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/plugin.py               plugin.py-20050622060424-829b654519533d69
      bzrlib/push.py                 push.py-20080606021927-5fe39050e8xne9un-1
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/smart/protocol.py       protocol.py-20061108035435-ot0lstk2590yqhzr-1
      bzrlib/smart/repository.py     repository.py-20061128022038-vr5wy5bubyb8xttk-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
      bzrlib/tests/blackbox/test_cat_revision.py test_cat_revision.py-20070410204634-fq8mnld5l5aza9e2-1
      bzrlib/tests/blackbox/test_info.py test_info.py-20060215045507-bbdd2d34efab9e0a
      bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
      bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
      bzrlib/tests/blackbox/test_missing.py test_missing.py-20051211212735-a2cf4c1840bb84c4
      bzrlib/tests/blackbox/test_non_ascii.py test_non_ascii.py-20060105214030-68010be784a5d854
      bzrlib/tests/blackbox/test_outside_wt.py test_outside_wt.py-20060116200058-98edd33e7db8bdde
      bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
      bzrlib/tests/blackbox/test_selftest.py test_selftest.py-20060123024542-01c5f1bbcb596d78
      bzrlib/tests/blackbox/test_send.py test_bundle.py-20060616222707-c21c8b7ea5ef57b1
      bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
      bzrlib/tests/branch_implementations/test_locking.py test_locking.py-20060707151933-tav3o2hpibwi53u4-4
      bzrlib/tests/branch_implementations/test_permissions.py test_permissions.py-20060210110243-245c01403bf0fde6
      bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
      bzrlib/tests/repository_implementations/test_commit_builder.py test_commit_builder.py-20060606110838-76e3ra5slucqus81-1
      bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
      bzrlib/tests/test__dirstate_helpers.py test_dirstate_helper-20070504035751-jsbn00xodv0y1eve-2
      bzrlib/tests/test_bundle.py    test.py-20050630184834-092aa401ab9f039c
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
      bzrlib/tests/test_dirstate.py  test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_fetch.py     testfetch.py-20050825090644-f73e07e7dfb1765a
      bzrlib/tests/test_index.py     test_index.py-20070712131115-lolkarso50vjr64s-2
      bzrlib/tests/test_info.py      test_info.py-20070320150933-m0xxm1g7xi9v6noe-1
      bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
      bzrlib/tests/test_merge.py     testmerge.py-20050905070950-c1b5aa49ff911024
      bzrlib/tests/test_options.py   testoptions.py-20051014093702-96457cfc86319a8f
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
      bzrlib/tests/test_pack_repository.py test_pack_repository-20080801043947-eaw0e6h2gu75kwmy-1
      bzrlib/tests/test_permissions.py test_permissions.py-20051215004520-ccf475789c80e80c
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_revisiontree.py test_revisiontree.py-20060615095324-aij44ndxbv1h4c9f-1
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
      bzrlib/tests/test_setup.py     test_setup.py-20051208073730-4a59a6368c4efa04
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/tests/test_upgrade_stacked.py test_upgrade_stacked-20080804072225-jd13yami19nskns5-1
      bzrlib/tests/test_whitebox.py  whitebox.py-20050530064534-a063aafb4a0a3a04
      bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
      bzrlib/tests/tree_implementations/test_walkdirs.py test_walkdirs.py-20060729160421-gmjnkotqgxdh98ce-1
      bzrlib/tests/workingtree_implementations/test_parents.py test_set_parents.py-20060807231740-yicmnlci1mj8smu1-1
      bzrlib/tests/workingtree_implementations/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
      bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
      bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
      bzrlib/transport/trace.py      trace.py-20070828055009-7kt0bbc4t4b92apz-1
      bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/development-repo.txt developmentrepo.txt-20080102200205-raj42k61dch8pjmj-1
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/developers/ppa.txt         ppa.txt-20080722055539-606u7t2z32t3ae4w-1
      doc/en/mini-tutorial/index.txt index.txt-20070813141352-2u64ooqzo0or4hss-2
      doc/en/user-guide/undoing_mistakes.txt undoing_mistakes.txt-20071121092300-8fyacngt1w98e5mp-1
      doc/es/mini-tutorial/index.txt index.txt-20080504182136-wmoc35u2t6kom8ca-1
      setup.py                       setup.py-20050314065409-02f8a0a6e3f9bc70
    ------------------------------------------------------------
    revno: 3642.2.2
    revision-id: jelmer at samba.org-20080821165821-r5vaoznc96k0kd18
    parent: jelmer at samba.org-20080821164547-3bmrt4u71v17j7ar
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: commit-message-template-hook
    timestamp: Thu 2008-08-21 18:58:21 +0200
    message:
      Add tests for commit_message_template hooks.
    modified:
      bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
      bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
    ------------------------------------------------------------
    revno: 3642.2.1
    revision-id: jelmer at samba.org-20080821164547-3bmrt4u71v17j7ar
    parent: pqm at pqm.ubuntu.com-20080820164550-e4vt9gdxv8hlic7n
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: commit-message-template-hook
    timestamp: Thu 2008-08-21 18:45:47 +0200
    message:
      Add simple commit message template hook.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
=== modified file 'NEWS'
--- a/NEWS	2008-11-11 00:57:17 +0000
+++ b/NEWS	2008-11-11 02:39:42 +0000
@@ -12,6 +12,9 @@
 
   NEW FEATURES:
 
+    * New ``commit_message_template`` hook that is called by the commit 
+      code to generate a template commit message. (Jelmer Vernooij)
+
     * New `shelve` and `unshelve` commands allow undoing and redoing changes.
       (Aaron Bentley)
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-11-03 21:52:46 +0000
+++ b/bzrlib/builtins.py	2008-11-10 22:42:21 +0000
@@ -2374,6 +2374,7 @@
         )
         from bzrlib.msgeditor import (
             edit_commit_message_encoded,
+            generate_commit_message_template,
             make_commit_message_template_encoded
         )
 
@@ -2408,7 +2409,9 @@
                 t = make_commit_message_template_encoded(tree,
                         selected_list, diff=show_diff,
                         output_encoding=osutils.get_user_encoding())
-                my_message = edit_commit_message_encoded(t)
+                start_message = generate_commit_message_template(commit_obj)
+                my_message = edit_commit_message_encoded(t, 
+                    start_message=start_message)
                 if my_message is None:
                     raise errors.BzrCommandError("please specify a commit"
                         " message with either --message or --file")

=== modified file 'bzrlib/help_topics/en/hooks.txt'
--- a/bzrlib/help_topics/en/hooks.txt	2008-10-29 06:10:45 +0000
+++ b/bzrlib/help_topics/en/hooks.txt	2008-11-11 00:46:06 +0000
@@ -261,3 +261,20 @@
 Runs on the client.
 
 (New in 1.8.)
+
+commit_message_template (msgeditor)
+-----------------------------------
+
+Invoked by commit to generate a commit message template.
+Each hook can modify the commit message template.
+The hook signature is (commit, start_message), where:
+
+  commit
+    A commit object, for the commit in progress
+
+  start_message
+    The original commit message, None initially.
+
+The hook should return a new commit message template.
+
+(New in 1.10.)

=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py	2008-09-14 10:23:29 +0000
+++ b/bzrlib/msgeditor.py	2008-11-11 00:46:06 +0000
@@ -28,7 +28,8 @@
     osutils,
     )
 from bzrlib.errors import BzrError, BadCommitMessageEncoding
-from bzrlib.trace import warning
+from bzrlib.hooks import Hooks
+from bzrlib.trace import warning, mutter
 
 
 def _get_editor():
@@ -268,3 +269,42 @@
         template = template + '\n' + stream.getvalue()
 
     return template
+
+
+class MessageEditorHooks(Hooks):
+    """A dictionary mapping hook name to a list of callables for message editor
+    hooks.
+
+    e.g. ['commit_message_template'] is the list of items to be called to 
+    generate a commit message template
+    """
+
+    def __init__(self):
+        """Create the default hooks.
+
+        These are all empty initially.
+        """
+        Hooks.__init__(self)
+        # Introduced in 1.10:
+        # Invoked to generate the commit message template shown in the editor
+        # The api signature is:
+        # (commit, message), and the function should return the new message
+        # There is currently no way to modify the order in which 
+        # template hooks are invoked
+        self['commit_message_template'] = []
+
+
+hooks = MessageEditorHooks()
+
+
+def generate_commit_message_template(commit, start_message=None):
+    """Generate a commit message template.
+
+    :param commit: Commit object for the active commit.
+    :param start_message: Message to start with.
+    :return: A start commit message or None for an empty start commit message.
+    """
+    start_message = None
+    for hook in hooks['commit_message_template']:
+        start_message = hook(commit, start_message)
+    return start_message

=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py	2008-09-08 12:59:00 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2008-11-11 00:13:03 +0000
@@ -23,6 +23,7 @@
 from bzrlib import (
     osutils,
     ignores,
+    msgeditor,
     osutils,
     )
 from bzrlib.bzrdir import BzrDir
@@ -595,3 +596,29 @@
             retcode=3)
         self.assertContainsRe(err,
             r'^bzr: ERROR: Cannot lock.*readonly transport')
+
+    def test_commit_hook_template(self):
+        # Test that commit template hooks work
+        def restoreDefaults():
+            msgeditor.hooks['commit_message_template'] = []
+            osutils.set_or_unset_env('BZR_EDITOR', default_editor)
+        if sys.platform == "win32":
+            f = file('fed.bat', 'w')
+            f.write('@rem dummy fed')
+            f.close()
+            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
+        else:
+            f = file('fed.sh', 'wb')
+            f.write('#!/bin/sh\n')
+            f.close()
+            os.chmod('fed.sh', 0755)
+            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
+        self.addCleanup(restoreDefaults)
+        msgeditor.hooks.install_named_hook("commit_message_template",
+                lambda commit_obj, msg: "save me some typing\n", None)
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/hello.txt'])
+        tree.add('hello.txt')
+        out, err = self.run_bzr("commit tree/hello.txt")
+        last_rev = tree.branch.repository.get_revision(tree.last_revision())
+        self.assertEqual('save me some typing\n', last_rev.message)

=== modified file 'bzrlib/tests/test_msgeditor.py'
--- a/bzrlib/tests/test_msgeditor.py	2008-09-08 12:59:00 +0000
+++ b/bzrlib/tests/test_msgeditor.py	2008-11-10 22:42:21 +0000
@@ -21,6 +21,7 @@
 import sys
 
 from bzrlib import (
+    commit,
     errors,
     msgeditor,
     osutils,
@@ -291,3 +292,18 @@
                               msgeditor.edit_commit_message, '')
         finally:
             osutils.set_or_unset_env('LANG', old_env)
+
+    def test_generate_commit_message_template_no_hooks(self):
+        commit_obj = commit.Commit()
+        self.assertIs(None, 
+            msgeditor.generate_commit_message_template(commit_obj))
+
+    def test_generate_commit_message_template_hook(self):
+        def restoreDefaults():
+            msgeditor.hooks['commit_message_template'] = []
+        self.addCleanup(restoreDefaults)
+        msgeditor.hooks.install_named_hook("commit_message_template",
+                lambda commit_obj, msg: "save me some typing\n", None)
+        commit_obj = commit.Commit()
+        self.assertEquals("save me some typing\n", 
+            msgeditor.generate_commit_message_template(commit_obj))




More information about the bazaar-commits mailing list