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
Document how to run pre-commit outside a git repo #2125
pre-commit can also be used as a tool for continuous integration. For instance, adding pre-commit run --all-files as a CI step will ensure everything stays in tip-top shape.
Unfortunately, my CI system's working folder is not a git repo. Instead the working folder appears to be a copy of the latest commit in a normal folder.*
It's unfortunate because pre-commit by design works only with git repos.
In #1894 it is shown how to work around the issue.
Is it possible to use pre-commit on files that are git-ignored (or even outside of a git repository)?
nope. the easiest is to git init && git add . if you need to
Could this be added to the documentation under the "Usage in continuous integration" section?
I'd make a PR myself, if you could point me to the docs.
* (I don't know how common a practice this is; the CI system on my current project is quite bespoke.)
An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
I'll grant you that it did help me track down the problem.
After adding the following test commands to my CI script:
git --version
git rev-parse --is-inside-work-tree
I determined that the working copy wasn't a git repo.
The message could be clearer because it could run those checks itself to be more exact about the problem. Whether it's worth the effort to include that is another question.
Searching the Github issues of the project lead me to the workaround you mentioned.
In the end I guess it comes down to how much support you want to give to the use case.
It will remain documented in the Github issues even if it doesn't make it into the main documentation.
I had also problems with the usage of pre-commit in combination with actions/checkout.
jobs:
format_job:
name: clang-formatruns-on: [self-hosted, Linux, X64, docker] container:
image: <<my-constainer-that-has-git-and-pre-commit-installed>>steps:
- uses: actions/checkout@v4# git checkout is not creating a working git folder, it has dubious ownership if not configured# The pre-commit hook will not work on this original git folder
- name: fix gitrun: git config --system --add safe.directory '*'
- name: Install pre-commit run: pre-commit install
- name: Run clang-format pre-commit check run: pre-commit run --all-files
With the addition of the git config --system -add safe.directory '*' it works
Activity
asottile commentedon Nov 11, 2021
I don't think it needs documenting since the error messages are clear
iainelder commentedon Nov 11, 2021
Hey, thanks for the quick response.
You mean this one?
I'll grant you that it did help me track down the problem.
After adding the following test commands to my CI script:
I determined that the working copy wasn't a git repo.
The message could be clearer because it could run those checks itself to be more exact about the problem. Whether it's worth the effort to include that is another question.
Searching the Github issues of the project lead me to the workaround you mentioned.
In the end I guess it comes down to how much support you want to give to the use case.
It will remain documented in the Github issues even if it doesn't make it into the main documentation.
asottile commentedon Nov 11, 2021
yeah makes sense, this is a fairly rare case
JonasVervoort commentedon Jul 31, 2024
I had also problems with the usage of pre-commit in combination with actions/checkout.
With the addition of the git config --system -add safe.directory '*' it works