mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Resolves cwd problem
This commit is contained in:
parent
6f0d566199
commit
216b5c6ab1
13 changed files with 212 additions and 107 deletions
|
|
@ -1,15 +1,17 @@
|
|||
|
||||
import subprocess
|
||||
|
||||
|
||||
def run_hook(env, hook, file_args):
|
||||
return env.run(
|
||||
' '.join(['xargs', hook['entry']] + hook.get('args', [])),
|
||||
stdin='\n'.join(list(file_args) + ['']),
|
||||
retcode=None,
|
||||
)
|
||||
|
||||
|
||||
class Environment(object):
|
||||
def __init__(self, repo_cmd_runner):
|
||||
self.repo_cmd_runner = repo_cmd_runner
|
||||
|
||||
@property
|
||||
def env_prefix(self):
|
||||
"""env_prefix is a value that is prefixed to the command that is run.
|
||||
|
|
@ -24,14 +26,8 @@ class Environment(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def run(self, cmd, stdin=None):
|
||||
def run(self, cmd, **kwargs):
|
||||
"""Returns (returncode, stdout, stderr)."""
|
||||
proc = subprocess.Popen(
|
||||
['bash', '-c', ' '.join([self.env_prefix, cmd])],
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
return self.repo_cmd_runner.run(
|
||||
['bash', '-c', ' '.join([self.env_prefix, cmd])], **kwargs
|
||||
)
|
||||
stdout, stderr = proc.communicate(stdin)
|
||||
|
||||
return proc.returncode, stdout, stderr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue