changeset 14864:1b872599f39f stable

cmdserver: restore old working dir after dispatch when we have --cwd
author Idan Kamara <idankk86@gmail.com>
date Mon, 11 Jul 2011 17:49:45 +0300
parents 1c148e935244
children eb914541a950
files mercurial/commandserver.py tests/test-commandserver.py tests/test-commandserver.py.out
diffstat 3 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commandserver.py	Mon Jul 11 17:46:55 2011 +0300
+++ b/mercurial/commandserver.py	Mon Jul 11 17:49:45 2011 +0300
@@ -7,7 +7,7 @@
 
 from i18n import _
 import struct
-import sys
+import sys, os
 import dispatch, encoding, util
 
 logfile = None
@@ -131,6 +131,7 @@
     based stream to stdout.
     """
     def __init__(self, ui, repo, mode):
+        self.cwd = os.getcwd()
         self.ui = ui
 
         logpath = ui.config("cmdserver", "log", None)
@@ -183,11 +184,15 @@
         self.repo.baseui = copiedui
         self.repo.ui = self.repo.dirstate._ui = self.repoui.copy()
 
-        req = dispatch.request(args, copiedui, self.repo, self.cin,
+        req = dispatch.request(args[:], copiedui, self.repo, self.cin,
                                self.cout, self.cerr)
 
         ret = dispatch.dispatch(req) or 0 # might return None
 
+        # restore old cwd
+        if '--cwd' in args:
+            os.chdir(self.cwd)
+
         self.cresult.write(struct.pack('>i', int(ret)))
 
     def getencoding(self):
--- a/tests/test-commandserver.py	Mon Jul 11 17:46:55 2011 +0300
+++ b/tests/test-commandserver.py	Mon Jul 11 17:49:45 2011 +0300
@@ -120,6 +120,15 @@
     runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
     runcommand(server, ['log'])
 
+def cwd(server):
+    """ check that --cwd doesn't persist between requests """
+    readchannel(server)
+    os.mkdir('foo')
+    open('foo/bar', 'w').write('a')
+    runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
+    runcommand(server, ['st', 'foo/bar'])
+    os.remove('foo/bar')
+
 if __name__ == '__main__':
     os.system('hg init')
 
@@ -128,3 +137,4 @@
     check(checkruncommand)
     check(inputeof)
     check(serverinput)
+    check(cwd)
--- a/tests/test-commandserver.py.out	Mon Jul 11 17:46:55 2011 +0300
+++ b/tests/test-commandserver.py.out	Mon Jul 11 17:49:45 2011 +0300
@@ -36,3 +36,5 @@
 date:        Thu Jan 01 00:00:00 1970 +0000
 summary:     1
 
+? bar
+? foo/bar