Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run pre-commit in gitlab CI

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.

like image 713
baxx Avatar asked Jun 18 '26 09:06

baxx


1 Answers

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.

like image 57
sytech Avatar answered Jun 20 '26 00:06

sytech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!