mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #622 from pre-commit/staged_files_only_patch_dir_does_not_exist
Do not crash in staged_files_only if patch_dir does not exist
This commit is contained in:
commit
c3c6175c94
2 changed files with 11 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import time
|
||||||
|
|
||||||
from pre_commit.util import CalledProcessError
|
from pre_commit.util import CalledProcessError
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
|
from pre_commit.util import mkdirp
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('pre_commit')
|
logger = logging.getLogger('pre_commit')
|
||||||
|
|
@ -43,6 +44,7 @@ def staged_files_only(patch_dir):
|
||||||
'Stashing unstaged files to {}.'.format(patch_filename),
|
'Stashing unstaged files to {}.'.format(patch_filename),
|
||||||
)
|
)
|
||||||
# Save the current unstaged changes as a patch
|
# Save the current unstaged changes as a patch
|
||||||
|
mkdirp(patch_dir)
|
||||||
with io.open(patch_filename, 'wb') as patch_file:
|
with io.open(patch_filename, 'wb') as patch_file:
|
||||||
patch_file.write(diff_stdout_binary)
|
patch_file.write(diff_stdout_binary)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,15 @@ def test_foo_something_unstaged(foo_staged, patch_dir):
|
||||||
_test_foo_state(foo_staged, 'herp\nderp\n', 'AM')
|
_test_foo_state(foo_staged, 'herp\nderp\n', 'AM')
|
||||||
|
|
||||||
|
|
||||||
|
def test_does_not_crash_patch_dir_does_not_exist(foo_staged, patch_dir):
|
||||||
|
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||||
|
foo_file.write('hello\nworld\n')
|
||||||
|
|
||||||
|
shutil.rmtree(patch_dir)
|
||||||
|
with staged_files_only(patch_dir):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_something_unstaged_ext_diff_tool(foo_staged, patch_dir, tmpdir):
|
def test_something_unstaged_ext_diff_tool(foo_staged, patch_dir, tmpdir):
|
||||||
diff_tool = tmpdir.join('diff-tool.sh')
|
diff_tool = tmpdir.join('diff-tool.sh')
|
||||||
diff_tool.write('#!/usr/bin/env bash\necho "$@"\n')
|
diff_tool.write('#!/usr/bin/env bash\necho "$@"\n')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue