pre-commit won’t run stage commit-msg local hooks

I’m having great difficulty making something that seems simple and logical but doesn’t work.

As part of a GitHub repository with Python code, I want to manage a pre-commit that will launch a python script (to check the commit message if there’s a keyword).

I use a Makefile (i’m on MacOS) to manage the config :

config:
    @echo "Install Git Hooks dependencies"
    python3 -m venv env 
      && source env/bin/activate 
      && pip install pre-commit
    pre-commit install --config .pre-commit-config.yaml

We can see in the 2 last rows of the output that pre-commit is correctly installed :

pre-commit install
pre-commit installed at .git/hooks/pre-commit

When the configuration is created, I activate the virtual environment:

source env/bin/activate

In the event of modification, I make my commit and everytime, the commit-msg won’t start. If I change the stage commit-msg to commit, the script will start but fail because it’s supposed to retreive the message…

% git commit -m "Testing"
check yaml...............................................................Passed
debug statements (python)............................(no files to check)Skipped
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
[main c8982a3] Testing
 3 files changed, 11 insertions(+), 4 deletions(-)

The pre-commit is launched, and we can see that it executes a local .sh script (which just returns a “Hello world”), but it never executes the python script.

I’ve tried absolutely everything with the arguments:

always_run: true # tired with false and without the arg always_run
pass_filenames: false # tired with true and without the arg pass_filename

Here is the .pre-commit-config.yaml

repos:
  - repo: local
    hooks:
      - id: validate-commit-message
        name: Validate Commit Message
        language: python
        entry: python commit_validation.py
        always_run: false
        pass_filenames: false
        stages: [commit-msg]
      - id: echo-hello
        name: Echo Hello
        entry: echo_hello.sh
        language: script
        always_run: true
        pass_filenames: false
        stages: [commit-msg]
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: check-yaml
      - id: debug-statements
      - id: end-of-file-fixer
      - id: trailing-whitespace

Even if I use pre-commit run --all-files the commit-msg won’t be triggered.

At this point, i’m totally lost.

Any ideas ?

If you want to run pre-commit on commit messages, you need to install the commit-msg hook:

pre-commit install -t commit-msg

Unrelated to your question, but note that there is a problem with the Makefile fragment you show in your question:

config:
    @echo "Install Git Hooks dependencies"
    python3 -m venv env 
      && source env/bin/activate 
      && pip install pre-commit
    pre-commit install --config .pre-commit-config.yaml

Each virtual line in a target runs in a separate subshell. That means the final pre-commit install ... command isn’t impacted by the source env/bin/activate command in the previous line. If pre-commit is running successfully, that suggests you’ve got it installed somewhere other than your virtual environment.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật