diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -233,7 +233,8 @@ def make_file(repo, pat, node=None, writable = 'w' in mode or 'a' in mode if not pat or pat == '-': - return writable and sys.stdout or sys.stdin + fp = writable and sys.stdout or sys.stdin + return os.fdopen(os.dup(fp.fileno()), mode) if hasattr(pat, 'write') and writable: return pat if hasattr(pat, 'read') and 'r' in mode: diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -73,8 +73,8 @@ test generic hooks [1] $ hg cat b pre-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] + b post-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] HG_RESULT=0 - b $ cd ../b $ hg pull ../a