# HG changeset patch
# User Idan Kamara <idankk86@gmail.com>
# Date 1307913566 -10800
#      Mon Jun 13 00:19:26 2011 +0300
# Node ID 25c1f3ddd9276f52e06cd21bc56a35d47fa591a6
# Parent  17c16bcf69265f37a6583e8c9df4e38afeba953a
dispatch: propagate ui command options to the local ui (issue2523)

so the ui object passed to pre/post python hooks has the verbose flag
(and the rest) set correctly

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -572,16 +572,20 @@
         atexit.register(print_time)
 
     if options['verbose'] or options['debug'] or options['quiet']:
-        ui.setconfig('ui', 'verbose', str(bool(options['verbose'])))
-        ui.setconfig('ui', 'debug', str(bool(options['debug'])))
-        ui.setconfig('ui', 'quiet', str(bool(options['quiet'])))
+        for ui in (ui, lui):
+            ui.setconfig('ui', 'verbose', str(bool(options['verbose'])))
+            ui.setconfig('ui', 'debug', str(bool(options['debug'])))
+            ui.setconfig('ui', 'quiet', str(bool(options['quiet'])))
     if options['traceback']:
-        ui.setconfig('ui', 'traceback', 'on')
+        for ui in (ui, lui):
+            ui.setconfig('ui', 'traceback', 'on')
     if options['noninteractive']:
-        ui.setconfig('ui', 'interactive', 'off')
+        for ui in (ui, lui):
+            ui.setconfig('ui', 'interactive', 'off')
 
     if cmdoptions.get('insecure', False):
-        ui.setconfig('web', 'cacerts', '')
+        for ui in (ui, lui):
+            ui.setconfig('web', 'cacerts', '')
 
     if options['help']:
         return commands.help_(ui, cmd, options['version'])
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -346,6 +346,9 @@
   > def brokenhook(**args):
   >     return 1 + {}
   > 
+  > def verbosehook(ui, **args):
+  >     ui.note('verbose output from hook\n')
+  > 
   > class container:
   >     unreachable = 1
   > EOF
@@ -535,3 +538,14 @@
   cb9a9f314b8b
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
+make sure --verbose (and --quiet/--debug etc.) are propogated to the local ui
+that is passed to pre/post hooks
+
+  $ echo '[hooks]' > .hg/hgrc
+  $ echo 'pre-identify = python:hooktests.verbosehook' >> .hg/hgrc
+  $ hg id
+  cb9a9f314b8b
+  $ hg id --verbose
+  calling hook pre-identify: hooktests.verbosehook
+  verbose output from hook
+  cb9a9f314b8b