Add --cwd global option, to change directory before doing anything.
authorBryan O'Sullivan <bos@serpentine.com>
Thu, 18 Aug 2005 14:58:14 -0800
changeset 943 e8e5db72ed51
parent 942 7eb8cbcca7c4
child 946 6d21a3488df9
Add --cwd global option, to change directory before doing anything. Useful for interacting with a program presenting a UI, such as Emacs.
mercurial/commands.py
--- a/mercurial/commands.py	Thu Aug 18 13:58:32 2005 -0800
+++ b/mercurial/commands.py	Thu Aug 18 14:58:14 2005 -0800
@@ -1404,6 +1404,7 @@
               ('', 'debug', None, 'debug mode'),
               ('q', 'quiet', None, 'quiet mode'),
               ('', 'profile', None, 'profile'),
+              ('C', 'cwd', '', 'change working directory'),
               ('R', 'repository', "", 'repository root directory'),
               ('', 'traceback', None, 'print traceback on exception'),
               ('y', 'noninteractive', None, 'run non-interactively'),
@@ -1492,6 +1493,14 @@
         help_(u, 'shortlist')
         sys.exit(1)
 
+    if options['cwd']:
+        try:
+            os.chdir(options['cwd'])
+        except OSError, inst:
+            u = ui.ui()
+            u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
+            sys.exit(1)
+
     if options["time"]:
         def get_times():
             t = os.times()