Skip to content

Commit

Permalink
Merge pull request #69 from lovato/feature/fixwin10newwindow
Browse files Browse the repository at this point in the history
Feature/fixwin10newwindow
  • Loading branch information
lovato committed Apr 10, 2020
2 parents d0056d2 + 05640e3 commit d2864db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions hooks4git/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def run_hook_cmd(command, files):
# backward compatibility to 0.3.x
if cmd[0:21] == "h4g/check_branch_name":
_command = shlex.split(command)
command = _command[0] + ' "' + _command[1] + '"'
command = _command[0]
if len(_command) > 1:
command = command + ' "' + _command[1] + '"'
# end

cmd_list = cmd.split("/")
Expand All @@ -112,7 +114,12 @@ def run_hook_cmd(command, files):
display_message += " " + _arg.replace(git_root, ".")[: (66 - len(display_message))] + "..."

display.say("STEP", "$ %s" % display_message)
code, result, err = os_call("%s %s" % (cmd, command.split(" ", 1)[1]))
params = ""
try:
params = command.split(" ", 1)[1]
except: # noqa # nosec
pass
code, result, err = os_call("%s %s" % (cmd, params))
result = result.strip().replace("\n", "\n".ljust(display.cmdbarwidth + 1) + "| ")
err = err.strip().replace("\n", "\n".ljust(display.cmdbarwidth + 1) + "| ")
if len(result) > 0:
Expand Down
14 changes: 12 additions & 2 deletions hooks4git/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ def os_call(command):
"""
Run system command.
"""
command = command.strip()
result_out = ""
result_err = ""
returncode = -1
try:
pipe1 = subprocess.PIPE
pipe2 = subprocess.PIPE
bash = None if "Windows" in get_platform() else "/bin/bash"
proc = subprocess.Popen(command, stdout=pipe1, stderr=pipe2, shell=True, executable=bash) # noqa # nosec
bash = "/bin/bash"
shell = True

if "Windows" in get_platform():
bash = None
shell = False
if "h4g" in command:
command = "/" + command[0].lower() + command[2:].replace(":\\", "/").replace("\\", "/") # noqa
command = 'c:\\Program Files\\Git\\bin\\bash.exe -c "' + command + '"' # noqa

proc = subprocess.Popen(command, stdout=pipe1, stderr=pipe2, shell=shell, executable=bash) # noqa # nosec
out, err = proc.communicate()
try:
tmp_out = out.decode("utf-8")
Expand Down

0 comments on commit d2864db

Please sign in to comment.