Skip to content

Using pre-commit on gitignored files, or outside of a git repo #1894

Closed

Description

@MatanRubin

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?

Activity

  1. asottile commented on Apr 30, 2021

    @asottile
    Member

    nope

    the easiest is to git init && git add . if you need to

  2. MatanRubin commented on Apr 30, 2021

    @MatanRubin
    Author

    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?

  3. asottile commented on Apr 30, 2021

    @asottile
    Member

    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

  4. MatanRubin commented on Apr 30, 2021

    @MatanRubin
    Author

    Fair enough, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions