3

I have a hook that generates documentation files from source files, built with the pre-commit.com framework. The function that is invoked in that hook does not have a file argument, so it simply creates documentation for all source files in the directory. The hook is a system hook, i.e. just a bash script where I call that function to create the documentation. However, in the pre-commit.com framework, files are passed to the hook and the logic is to execute a hook on every file, which makes sense in most cases (e.g. to lint every file separately). So my question is: How can I ensure that the documentation hook is run once if there is any source file changed, as opposed to it being run in multiple times (in parallel or sequentially), on the individual files? In concrete terms, my hook is generating R docuementation with roxygen2::roxygenize() and can be found here.

Lorenz Walthert
  • 4,414
  • 1
  • 18
  • 24
  • Looks similar to https://stackoverflow.com/questions/2412450/git-pre-commit-hook-changed-added-files – Rudi Jul 25 '19 at 10:44
  • 1
    I am not sure. My question is very specific to the pre-commit.com framework. I updated the question to reflect that better. – Lorenz Walthert Jul 25 '19 at 10:53
  • This sounds like you are trying to bend a system designed for use case *A* to apply to completely-different use-case *H*. It might be better to look into a system that's not so tied to the one-file-at-a-time use-case. – torek Jul 25 '19 at 15:59

1 Answers1

8

The pre-commit framework supports a pass_filenames: false

The docs could perhaps be improved here but this is what they have to say

pass_filenames - (optional: default true) if true this hook must take filenames as positional arguments. new in 0.14.0.

hmmm yeah maybe not the best description -- but if false pre-commit will only invoke your command once and won't pass any filenames

anthony sottile
  • 61,815
  • 15
  • 148
  • 207