pythongitpre-commit-hookpre-commitpre-commit.com

Pre-commit shows different result when running directly in command line vs running from make


I have a Makefile that contains this:

SOURCE_DIR=./some_codebase/**/*

check-mypy:
    pre-commit run mypy --files $(SOURCE_DIR)

When I trigger make check-mypy, the result shows up as Passed (which is not correct), but when I run pre-commit run mypy --files ./some_codebase/**/* directly in the command line, the result shows up as Failed (which is correct). Another thing to point out is that I use mypy in this question only as an example, all other hooks have this issue as well (I also use ruff/black). This issue also happens in my bitbucket pipeline.

$ make check-mypy
pre-commit run mypy --files ./pyworker_v2/**/*
mypy.....................................................................Passed
$ pre-commit run mypy --files ./pyworker_v2/**/*
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

My .pre-commit-config.yaml is as below:

minimum_pre_commit_version: 3.3.3

repos:
  - repo: local
    hooks:
      - id: mypy
        name: mypy
        entry: mypy --config-file ./pyproject.toml --enable-incomplete-feature=Unpack --install-types --non-interactive
        language: system
        types: [python]

I've tried running the command through a bash script and weirdly enough, the check shows up as Passed again (not correct), so this is not just an issue with the Makefile.

#!/bin/bash

pre-commit run mypy --files ./pyworker_v2/**/*

I also tried:


Solution

  • This isn't a git issue, but a Make & shell one.

    You're (presumably) using zsh as your interactive shell, which supports the ** recursive wildcard as an extension to the original glob expansion.

    Neither bash, for your bash script, nor GNU Make (which uses the same glob expansion as bash AFAIK) support this zsh extension.