I have a git repo with a couple of submodules whose code contents are out of my control. I would like to ignore these submodules in all pre-commit hooks. Is there any way of achieving this short of manually specifying the folders in which these submodules reside for every individual hook?
Asked
Active
Viewed 907 times
1
-
I think this is the automatic behaviour, your repo won't see submodule changes unless you `git submodule update`. If you have local changes in those submodules you could `checkout` them if you don't need them – Ivan Apr 15 '21 at 08:08
1 Answers
1
submodules should be ignored by default -- they get a special type
tag of submodule
which usually doesn't go through the normal git hooks (which by default have a filter of [file]
).
my guess is your configuration escapes the normal way of using hooks and does something like flake8 .
-- in which case you should switch to filename-based hooks. It's impossible to know without seeing your configuration though so please share that with an edit
disclaimer: I'm the creator of pre-commit

anthony sottile
- 61,815
- 15
- 148
- 207
-
This is the specific hook that's causing trouble: https://github.com/andreoliwa/nitpick/blob/develop/.pre-commit-hooks.yaml – RoyalTS Apr 16 '21 at 08:08
-
@RoyalTS -- yeah both of those have problems, the `flake8` one will run against all files in your repository if nothing changes due to misuse of `always_run`. and `nitpick run` unconditionally checks every file always. they've sidestepped the framework and you should open an issue asking them to change to linting filenames which are passed – anthony sottile Apr 16 '21 at 13:44
-
@AnthonySottile Is there any way to check default types of each hook? My test shows that the default types of `flake8` is `[python]` rather than `[file]`. – drowsyleilei Sep 22 '21 at 10:42
-
@AnthonySottile My test shows that submodules are indeed ignored by default. However, as I check with identify-cli, both a submodule and a folder return the type "directory", so how does pre-commit know which one to ignore? – drowsyleilei Sep 22 '21 at 10:43
-
@drowsyleilei you can't check "a folder" into git (only files) so only submodules are relevant – anthony sottile Sep 22 '21 at 12:43
-