mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-02 10:56:52 +00:00
forbid-new-submodules: fix triggering failure when only a submodule is committed (without any other file); support --from-ref and --to-ref; fixes #609
This commit is contained in:
parent
8c1183c0c8
commit
10c5e4e166
9 changed files with 65 additions and 25 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import argparse
|
||||
import os
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
|
||||
|
|
@ -5,10 +7,23 @@ from pre_commit_hooks.util import cmd_output
|
|||
|
||||
|
||||
def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||
# `argv` is ignored, pre-commit will send us a list of files that we
|
||||
# don't care about
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
if (
|
||||
'PRE_COMMIT_FROM_REF' in os.environ and
|
||||
'PRE_COMMIT_TO_REF' in os.environ
|
||||
):
|
||||
diff_arg = '...'.join((
|
||||
os.environ['PRE_COMMIT_FROM_REF'],
|
||||
os.environ['PRE_COMMIT_TO_REF'],
|
||||
))
|
||||
else:
|
||||
diff_arg = '--staged'
|
||||
added_diff = cmd_output(
|
||||
'git', 'diff', '--staged', '--diff-filter=A', '--raw',
|
||||
'git', 'diff', '--diff-filter=A', '--raw', diff_arg, '--',
|
||||
*args.filenames,
|
||||
)
|
||||
retv = 0
|
||||
for line in added_diff.splitlines():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue