Search code examples
pre-commit-hookpre-commitpre-commit.com

Is possible to list the files affected by pre-commit run?


While using pre-commit sometimes I just want to know that filenames are going to be passed to the hook, just to verify that by --from-ref and to-ref are correct. For example, I was running:

pre-commit run flake8  --from-ref $(git merge-base master HEAD) --to-ref HEAD

and I wasn't sure of what files where passed to my flake8 hook, adding --verbose does not help because flake8 will not output the filenames either.

So it's there any way to tell pre-commit to only output the list of filenames without running the actual hook?


Solution

  • pre-commit provides a special identity hook for this purpose

    you can configure it by doing:

    -   repo: meta
        hooks:
        -   id: identity
    

    alternatively, if you're just trying to figure out --from-ref / --to-ref -- you can use git diff A...B --name-only as that's what pre-commit is using behind the scenes


    disclaimer: I'm the author of pre-commit