Rev 3277: (Daniel Mark Watkins) Add the hooks command in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Mar 14 21:17:05 GMT 2008


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

------------------------------------------------------------
revno: 3277
revision-id:pqm at pqm.ubuntu.com-20080314211658-bjlcjsk0zl2ppcai
parent: pqm at pqm.ubuntu.com-20080314152947-u92b6klpfcnigv4e
parent: ian.clatworthy at canonical.com-20080314194424-p4u1imde9iib89rm
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-03-14 21:16:58 +0000
message:
  (Daniel Mark Watkins) Add the hooks command
added:
  bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
  doc/en/user-guide/hooks.txt    hooks.txt-20070829200551-7nr6e5a1io6x78uf-1
    ------------------------------------------------------------
    revno: 3276.1.1
    revision-id:ian.clatworthy at canonical.com-20080314194424-p4u1imde9iib89rm
    parent: pqm at pqm.ubuntu.com-20080314152947-u92b6klpfcnigv4e
    parent: d.m.watkins at warwick.ac.uk-20080311004546-ym26xuisj59bus06
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: ianc-integration
    timestamp: Fri 2008-03-14 14:44:24 -0500
    message:
      (Daniel Mark Watkins) Add the hooks command
    added:
      bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
      doc/en/user-guide/hooks.txt    hooks.txt-20070829200551-7nr6e5a1io6x78uf-1
    ------------------------------------------------------------
    revno: 3254.2.11
    revision-id:d.m.watkins at warwick.ac.uk-20080311004546-ym26xuisj59bus06
    parent: d.m.watkins at warwick.ac.uk-20080311003525-38qdc4nmol98y8cd
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hook-type-descriptions
    timestamp: Tue 2008-03-11 00:45:46 +0000
    message:
      Added some information to the user guide regarding 'bzr hooks'.
    modified:
      doc/en/user-guide/hooks.txt    hooks.txt-20070829200551-7nr6e5a1io6x78uf-1
    ------------------------------------------------------------
    revno: 3254.2.10
    revision-id:d.m.watkins at warwick.ac.uk-20080311003525-38qdc4nmol98y8cd
    parent: d.m.watkins at warwick.ac.uk-20080308230423-fc2uuta6robt6en1
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hook-type-descriptions
    timestamp: Tue 2008-03-11 00:35:25 +0000
    message:
      Added NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3254.2.9
    revision-id:d.m.watkins at warwick.ac.uk-20080308230423-fc2uuta6robt6en1
    parent: d.m.watkins at warwick.ac.uk-20080308194820-d0fin7xrpzqdjyca
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: cmd_hooks
    timestamp: Sat 2008-03-08 23:04:23 +0000
    message:
      Made cmd_hooks hidden.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
    ------------------------------------------------------------
    revno: 3254.2.8
    revision-id:d.m.watkins at warwick.ac.uk-20080308194820-d0fin7xrpzqdjyca
    parent: d.m.watkins at warwick.ac.uk-20080308182544-sw9fi33k7wu5rku7
    parent: pqm at pqm.ubuntu.com-20080307231150-h9ct4c51ekdiexbs
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 19:48:20 +0000
    message:
      Merged bzr.dev.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/debug.py                debug.py-20061102062349-vdhrw9qdpck8cl35-1
      bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/merge_directive.py      merge_directive.py-20070228184838-ja62280spt1g7f4x-1
      bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
    ------------------------------------------------------------
    revno: 3254.2.7
    revision-id:d.m.watkins at warwick.ac.uk-20080308182544-sw9fi33k7wu5rku7
    parent: d.m.watkins at warwick.ac.uk-20080308182502-3nw80f91y81tr9fp
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 18:25:44 +0000
    message:
      Added hook to ensure that 'bzr hooks' can deal with named plugins.
    modified:
      bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
    ------------------------------------------------------------
    revno: 3254.2.6
    revision-id:d.m.watkins at warwick.ac.uk-20080308182502-3nw80f91y81tr9fp
    parent: d.m.watkins at warwick.ac.uk-20080308172132-t4saylt7kzw1on1j
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 18:25:02 +0000
    message:
      Increased test granularity.
    modified:
      bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
    ------------------------------------------------------------
    revno: 3254.2.5
    revision-id:d.m.watkins at warwick.ac.uk-20080308172132-t4saylt7kzw1on1j
    parent: d.m.watkins at warwick.ac.uk-20080308164605-qqaz6zd19l7clnkl
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 17:21:32 +0000
    message:
      Tests now ensure that some output is given when a hook is installed.
    modified:
      bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
    ------------------------------------------------------------
    revno: 3254.2.4
    revision-id:d.m.watkins at warwick.ac.uk-20080308164605-qqaz6zd19l7clnkl
    parent: d.m.watkins at warwick.ac.uk-20080308164419-2y3dvp8twu3betrn
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 16:46:05 +0000
    message:
      Changed output to conform to tests.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
    ------------------------------------------------------------
    revno: 3254.2.3
    revision-id:d.m.watkins at warwick.ac.uk-20080308164419-2y3dvp8twu3betrn
    parent: d.m.watkins at warwick.ac.uk-20080308163528-7dt4fd55pqe13m9v
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 16:44:19 +0000
    message:
      Added a test to ensure correct default output.
    modified:
      bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
    ------------------------------------------------------------
    revno: 3254.2.2
    revision-id:d.m.watkins at warwick.ac.uk-20080308163528-7dt4fd55pqe13m9v
    parent: d.m.watkins at warwick.ac.uk-20080308162940-4hrc1g642aexq0aa
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 16:35:28 +0000
    message:
      Added test_hooks stub.
    added:
      bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
    modified:
      bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
    ------------------------------------------------------------
    revno: 3254.2.1
    revision-id:d.m.watkins at warwick.ac.uk-20080308162940-4hrc1g642aexq0aa
    parent: pqm at pqm.ubuntu.com-20080306171300-yr2n8r9w4a4ettbo
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: hooks
    timestamp: Sat 2008-03-08 16:29:40 +0000
    message:
      Added cmd_hooks.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
=== added file 'bzrlib/tests/blackbox/test_hooks.py'
--- a/bzrlib/tests/blackbox/test_hooks.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/blackbox/test_hooks.py	2008-03-08 18:25:44 +0000
@@ -0,0 +1,54 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for commands related to hooks"""
+
+from bzrlib.branch import Branch
+from bzrlib.tests import TestCaseWithTransport
+
+
+class TestHooks(TestCaseWithTransport):
+
+    def _check_hooks_output(self, command_output, hooks):
+        for hook_type in Branch.hooks:
+            s = "\n  ".join(hooks.get(hook_type, ["<no hooks installed>"]))
+            self.assert_("%s:\n  %s" % (hook_type, s) in command_output)
+
+    def test_hooks_with_no_hooks(self):
+        self.make_branch('.')
+        out, err = self.run_bzr('hooks')
+        self.assertEqual(err, "")
+        for hook_type in Branch.hooks:
+            self._check_hooks_output(out, {})
+
+    def test_hooks_with_unnamed_hook(self):
+        self.make_branch('.')
+        def foo(): return
+        Branch.hooks.install_hook('set_rh', foo)
+        out, err = self.run_bzr('hooks')
+        self._check_hooks_output(out, {'set_rh': ["No hook name"]})
+
+    def test_hooks_with_named_hook(self):
+        self.make_branch('.')
+        def foo(): return
+        name = "Foo Bar Hook"
+        Branch.hooks.install_hook('set_rh', foo)
+        Branch.hooks.name_hook(foo, name)
+        out, err = self.run_bzr('hooks')
+        self._check_hooks_output(out, {'set_rh': [name]})
+
+    def test_hooks_no_branch(self):
+        self.run_bzr('hooks', retcode=3)

=== modified file 'NEWS'
--- a/NEWS	2008-03-14 01:19:27 +0000
+++ b/NEWS	2008-03-14 19:44:24 +0000
@@ -60,6 +60,9 @@
      case of running ``bzr missing`` command for two identical branches.
      (Alexander Belchenko)
 
+   * The ``hooks`` command lists installed hooks, to assist in debugging.
+     (Daniel Watkins)
+
   BUGFIXES:
 
     * Disable plink's interactive prompt for password.

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-03-14 01:19:27 +0000
+++ b/bzrlib/builtins.py	2008-03-14 19:44:24 +0000
@@ -4452,6 +4452,28 @@
             urlutils.unescape_for_display(to_branch.base, 'utf-8'))
 
 
+class cmd_hooks(Command):
+    """Show a branch's currently registered hooks.
+    """
+
+    hidden = True
+    takes_args = ['path?']
+
+    def run(self, path=None):
+        if path is None:
+            path = '.'
+        branch_hooks = Branch.open(path).hooks
+        for hook_type in branch_hooks:
+            hooks = branch_hooks[hook_type]
+            self.outf.write("%s:\n" % (hook_type,))
+            if hooks:
+                for hook in hooks:
+                    self.outf.write("  %s\n" %
+                                    (branch_hooks.get_hook_name(hook),))
+            else:
+                self.outf.write("  <no hooks installed>\n")
+
+
 def _create_prefix(cur_transport):
     needed = [cur_transport]
     # Recurse upwards until we can create a directory successfully

=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py	2007-11-21 15:10:44 +0000
+++ b/bzrlib/tests/blackbox/__init__.py	2008-03-08 16:35:28 +0000
@@ -64,6 +64,7 @@
                      'bzrlib.tests.blackbox.test_export',
                      'bzrlib.tests.blackbox.test_find_merge_base',
                      'bzrlib.tests.blackbox.test_help',
+                     'bzrlib.tests.blackbox.test_hooks',
                      'bzrlib.tests.blackbox.test_ignore',
                      'bzrlib.tests.blackbox.test_ignored',
                      'bzrlib.tests.blackbox.test_info',

=== modified file 'doc/en/user-guide/hooks.txt'
--- a/doc/en/user-guide/hooks.txt	2007-12-17 02:00:45 +0000
+++ b/doc/en/user-guide/hooks.txt	2008-03-11 00:45:46 +0000
@@ -49,3 +49,10 @@
 
 For a complete list of hooks and their parameters, see `Hooks
 <../user-reference/bzr_man.html#hooks>`_ in the User Reference.
+
+Debugging hooks
+---------------
+
+To get a list of installed hooks, use the hidden ``hooks`` command::
+
+    bzr hooks




More information about the bazaar-commits mailing list