mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Add check_path hook
Adds a hook which can be used for preventing commits to paths specified by regex.
This commit is contained in:
parent
f0bf512dbb
commit
ade67be453
5 changed files with 96 additions and 0 deletions
45
tests/check_path_edits_test.py
Normal file
45
tests/check_path_edits_test.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from pre_commit_hooks.check_path_edits import find_wrong_paths
|
||||
from pre_commit_hooks.check_path_edits import main
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def test_nothing_added(temp_git_dir):
|
||||
with temp_git_dir.as_cwd():
|
||||
assert find_wrong_paths(['f.py'], {'asd'}) == 0
|
||||
|
||||
|
||||
def test_adding_something(temp_git_dir):
|
||||
with temp_git_dir.as_cwd():
|
||||
temp_git_dir.join('f.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert find_wrong_paths(['f.py'], {'^f.*'}) == 1
|
||||
|
||||
|
||||
def test_some_regex(temp_git_dir):
|
||||
with temp_git_dir.as_cwd():
|
||||
temp_git_dir.join('f.py').write('a' * 10000)
|
||||
|
||||
# Should not fail when not added
|
||||
assert find_wrong_paths(['f.py'], {'.*'}) == 0
|
||||
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert find_wrong_paths(['f.py'], {'.*'}) == 1
|
||||
|
||||
assert find_wrong_paths(['f.py'], {'dasd', 'py', 'asd'}) == 1
|
||||
|
||||
assert find_wrong_paths(['f.py'], {'^py'}) == 0
|
||||
|
||||
|
||||
def test_integration(temp_git_dir):
|
||||
with temp_git_dir.as_cwd():
|
||||
assert main(argv=[]) == 0
|
||||
|
||||
temp_git_dir.join('f.py').write('a')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
# Should not fail with default
|
||||
assert main(argv=['f.py']) == 0
|
||||
|
||||
assert main(argv=['--pattern', 'f.py', 'f.py']) == 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue