I tried setting up a job as follows in my .gitlab-ci.yml file:
precommit:
image: python:3.10.2-slim-bullseye
before_script:
- pip install -r requirements.txt
script:
- pre-commit run --all-files
But the following error is output :
$ pre-commit run --all-files
An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
I checked that there was a .git where the command was being used from - and there is - so I'm not sure why this particular error is being flagged, or how to fix it.
The python:3.10 image does not include git which is needed by pre-commit.
Install git to resolve the issue:
precommit:
image: python:3.10.2-slim-bullseye
before_script:
- apt update && apt install -y --no-install-recommends git
- pip install -r requirements.txt
# ...
As a side note, maybe also consider taking a look at this SO article explaining use of pre-commit in gitlab and the additional references contained therein.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With