mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 12:06:53 +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
31
pre_commit_hooks/forbid_new_submodules.py
Normal file
31
pre_commit_hooks/forbid_new_submodules.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
# `argv` is ignored, pre-commit will send us a list of files that we
|
||||
# don't care about
|
||||
added_diff = cmd_output(
|
||||
'git', 'diff', '--staged', '--diff-filter=A', '--raw',
|
||||
)
|
||||
retv = 0
|
||||
for line in added_diff.splitlines():
|
||||
metadata, filename = line.split('\t', 1)
|
||||
new_mode = metadata.split(' ')[1]
|
||||
if new_mode == '160000':
|
||||
print('{}: new submodule introduced'.format(filename))
|
||||
retv = 1
|
||||
|
||||
if retv:
|
||||
print('This commit introduces new submodules.')
|
||||
print('Did you unintentionally `git add .`?')
|
||||
print('To fix: git rm {thesubmodule} # no trailing slash')
|
||||
print('Also check .gitmodules')
|
||||
|
||||
return retv
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue