On Windows we can't simply run the hook script directly, since it's not a batch file. Instead, explicitly call bash to run the hook.
Also, on Windows NamedTemporaryFile opens the temporary file with the flag O_TEMPORARY to automatically delete it when it is closed, and that means that to reopen the same file requires passing O_TEMPORARY again (or, more specifically, they must open it with the FILE_SHARE_DELETE sharing flag in the underlying Win32 API. See http://bugs.python.org/issue14243#msg164514 for gory details). To avoid using this flag, pass delete=False and just clean up the file explicitly when we're done. Signed-off-by: Zane Bitter <[email protected]> Tested-by: Jamie Madill <[email protected]> --- stgit/utils.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/stgit/utils.py b/stgit/utils.py index 83679d4..73bed7a 100644 --- a/stgit/utils.py +++ b/stgit/utils.py @@ -205,6 +205,10 @@ def get_hook(repository, hook_name, extra_env={}): argv = [hook_path] argv.extend(parameters) + # On Windows, run the hook using "bash" explicitly + if os.name != 'posix': + argv.insert(0, 'bash') + default_iw.run(argv, extra_env).run() hook.__name__ = hook_name @@ -212,20 +216,22 @@ def get_hook(repository, hook_name, extra_env={}): def run_hook_on_string(hook, s, *args): if hook is not None: - temp = tempfile.NamedTemporaryFile('w') + temp = tempfile.NamedTemporaryFile('wb', delete=False) try: - temp.write(s) - temp.flush() + try: + temp.write(s) + finally: + temp.close() hook(temp.name, *args) - output = open(temp.name, 'r') + output = open(temp.name, 'rb') try: s = output.read() finally: output.close() finally: - temp.close() + os.unlink(temp.name) return s _______________________________________________ stgit-users mailing list [email protected] https://mail.gna.org/listinfo/stgit-users
