mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-15 21:40:19 -06:00
Add staged_files_only context manager.
This commit is contained in:
@@ -6,6 +6,9 @@ import subprocess
|
||||
|
||||
class CalledProcessError(RuntimeError):
|
||||
def __init__(self, returncode, cmd, expected_returncode, output=None):
|
||||
super(CalledProcessError, self).__init__(
|
||||
returncode, cmd, expected_returncode, output,
|
||||
)
|
||||
self.returncode = returncode
|
||||
self.cmd = cmd
|
||||
self.expected_returncode = expected_returncode
|
||||
@@ -15,13 +18,13 @@ class CalledProcessError(RuntimeError):
|
||||
return (
|
||||
'Command: {0!r}\n'
|
||||
'Return code: {1}\n'
|
||||
'Expected return code {2}\n',
|
||||
'Expected return code: {2}\n'
|
||||
'Output: {3!r}\n'.format(
|
||||
self.cmd,
|
||||
self.returncode,
|
||||
self.expected_returncode,
|
||||
self.output,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -48,15 +51,15 @@ class PrefixedCommandRunner(object):
|
||||
self.__makedirs(self.prefix_dir)
|
||||
|
||||
def run(self, cmd, retcode=0, stdin=None, **kwargs):
|
||||
popen_kwargs = {
|
||||
'stdin': subprocess.PIPE,
|
||||
'stdout': subprocess.PIPE,
|
||||
'stderr': subprocess.PIPE,
|
||||
}
|
||||
popen_kwargs.update(kwargs)
|
||||
self._create_path_if_not_exists()
|
||||
replaced_cmd = _replace_cmd(cmd, prefix=self.prefix_dir)
|
||||
proc = self.__popen(
|
||||
replaced_cmd,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
**kwargs
|
||||
)
|
||||
proc = self.__popen(replaced_cmd, **popen_kwargs)
|
||||
stdout, stderr = proc.communicate(stdin)
|
||||
returncode = proc.returncode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user