mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 19:26:52 +00:00
Add a new hook to forbid new submodules
This commit is contained in:
parent
7539d8bd1a
commit
70e405ede2
7 changed files with 75 additions and 5 deletions
39
tests/forbid_new_submodules_test.py
Normal file
39
tests/forbid_new_submodules_test.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
from pre_commit.util import cmd_output
|
||||
|
||||
from pre_commit_hooks.forbid_new_submodules import main
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def git_dir_with_git_dir(tmpdir):
|
||||
with tmpdir.as_cwd():
|
||||
cmd_output('git', 'init', '.')
|
||||
cmd_output('git', 'commit', '-m', 'init', '--allow-empty')
|
||||
cmd_output('git', 'init', 'foo')
|
||||
with tmpdir.join('foo').as_cwd():
|
||||
cmd_output('git', 'commit', '-m', 'init', '--allow-empty')
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'cmd',
|
||||
(
|
||||
# Actually add the submodule
|
||||
('git', 'submodule', 'add', './foo'),
|
||||
# Sneaky submodule add (that doesn't show up in .gitmodules)
|
||||
('git', 'add', 'foo'),
|
||||
),
|
||||
)
|
||||
def test_main_new_submodule(git_dir_with_git_dir, capsys, cmd):
|
||||
cmd_output(*cmd)
|
||||
assert main() == 1
|
||||
out, _ = capsys.readouterr()
|
||||
assert out.startswith('foo: new submodule introduced\n')
|
||||
|
||||
|
||||
def test_main_no_new_submodule(git_dir_with_git_dir):
|
||||
open('test.py', 'a+').close()
|
||||
cmd_output('git', 'add', 'test.py')
|
||||
assert main() == 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue