You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using pre-commit on gitignored files, or outside of a git repo #1894
Is it possible to use pre-commit on files that are git-ignored (or even outside of a git repository)?
I know pre-commit is meant to be used, ahm, pre commit. But it turns out that pre-commit is super useful for running various tools without having to deal with installing them manually.
My specific use case is this: I'm working on a code-generation project. All generated code goes into a build directory which is gitignored (since the generated code is packaged and pushed to a package registry).
I want to be able to use pre-commit to run "black" on the generated python code before packaging it, "google-java-formatter" on the generated java code, etc. Is such a use case supported and/or possible somehow?
Assuming the main challenge is to change the way pre-commit determines which files to work on, I'd be happy to give it a try and issue a PR. Is that something you'd be interested in?
yes, pre-commit only operates on files which are in git, so running on things which are not in git is the opposite of what it is designed to do -- and there's an easy way around it -- add the files to a git repo
I am not interested in a PR for this so please do not submit one
Reacted by Iain Samuel McLean Elder and ebokai
Reacted by Eric Berquist, Bob Stockdale, Ali Firooz, Chrysus, Tim Burgess, Ⲡⲓϣⲱⲓ, Bakary N'tji Diallo and Plamen Nedkov
Activity
asottile commentedon Apr 30, 2021
nope
the easiest is to
git init && git add .if you need toMatanRubin commentedon Apr 30, 2021
Is there a reason not to support such a use case?
Assuming the main challenge is to change the way pre-commit determines which files to work on, I'd be happy to give it a try and issue a PR. Is that something you'd be interested in?
asottile commentedon Apr 30, 2021
yes, pre-commit only operates on files which are in
git, so running on things which are not ingitis the opposite of what it is designed to do -- and there's an easy way around it -- add the files to a git repoI am not interested in a PR for this so please do not submit one
MatanRubin commentedon Apr 30, 2021
Fair enough, thanks!