observing / pre-commit

Automatically installs a git pre-commit script in your git repository which runs your `npm test` on pre-commit
MIT License
1.88k stars 153 forks source link

How to run pre-commit hook in docker container? #156

Open heatherKoo07 opened 2 years ago

heatherKoo07 commented 2 years ago

Hi, I want to run pre-commit hook in my docker container as I moved my dev environment to the docker.

By default, pre-commit requires npm install in local environment to run ./node_modules/pre-commit/hook in .git/hooks/pre-commit script.

When I did some research, I found this link https://spectrum.chat/node/general/pre-commit-with-docker~840290ba-1cb6-40e2-a7ad-7566054638b8. I changed the first line of the pre-commit script manually as below and it worked as expected although it's quite slow.

#!/bin/bash
docker-compose run --rm web sh ./node_modules/pre-commit/hook # web is my docker-compose service name
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0

Is there a way to customize pre-commit script in configuration or something? (rather than manual change)

Thanks