git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Issue with git > 2.36.1 and pre-commit hook on macOS M1

From
PPiotrek <piotrekkr@o2.pl>
Date
Dec 11, 2022, 21:11 UTC
Message-ID
<51d5993f-a1e0-519e-ffa9-ec5205c5e96d@o2.pl>
Hello.

On MacOS 12.6.1 with M1 chip, git >=2.37.0 (installed by homebrew) and pre-commit hook that is calling *make* target, that is calling *docker compose run* command, we get error:

     the input device is not a TTY
All works file with homebrew git version 2.36.1
* DETAILS OF PROBLEM *

There is pre-commit hook in place that is using bash script to call `make` command which is in turn calling `docker compose run` to run some check before commit. After upgrading git version from `2.36.1` to `>=2.37` we constantly get error:

 > the input device is not a TTY
Example pre-commit hook output:
 > docker compose run --rm --entrypoint "" app /code/test.sh
 > the input device is not a TTY
 > make: *** [Makefile:6: check] Error 1
 > !!! FAILING REGARDLESS OF CHECK RESULT !!!
(the latest error message is just so we don't actually commit anything)

AFAIK `docker compose` command is auto-detecting TTY because no `-t` or `-T` were set.

By doing some tests we managed to check that it is a problem with `git` version.

Latest version that it worked was `2.36.1`:
 > docker compose run --rm --entrypoint "" app /code/test.sh
 > =================== CHECK OK =================
 > !!! FAILING REGARDLESS OF CHECK RESULT !!!
Machine and software we were testing on:
 > make --version
 > GNU Make 3.81
 >
 > docker compose version
 > Docker Compose version v2.12.2
 >
 > git --version
 > git version 2.38.1
 >
 > which git
 > /opt/homebrew/bin/git

Also, we tested with linux Ubuntu and all git versions are working fine with same pre-commit hook. It seems related to `macOS` and `git` only.

* REPLICATING THIS PROBLEM *
Easiest way top replicate is to just clone sample repo I prepared here:
https://github.com/piotrekkr/git-tty-issue-macos
and go with replicate instructions from README.md.

If this is not okay then below I will copy and paste instruction with file contents.

* FILES *
* Makefile *
     COMPOSE_RUN = docker compose run --rm --entrypoint ""
     check:
     	$(COMPOSE_RUN) app /code/test.sh
* docker-compose.yml *
     version: "3.7"
     services:
     app:
         image: php:8.1.3-fpm-bullseye
         volumes:
         - "${PWD}:/code"
         working_dir: /code
* .git/hooks/pre-commit *
     #!/usr/bin/env bash
     make check
     echo "!!! FAILING REGARDLESS OF CHECK RESULT !!!"
     exit 1
* test.sh *
     #!/usr/bin/env bash
     echo "=================== CHECK OK ================="

(sorry for attaching like that, I'm not good with those plain text mail lists)

* INSTRUCTIONS *
1. have macOS with M1 chip (can be expensive)
2. install `docker`, `docker compose v2`, `make`
3. upgrade git with homebrew to version `>=2.37.0`
4. clone repo or manually create files (in same directory)
    - Makefile
    - docker-compose.yml
    - .git/hooks/pre-commit (with execute permissions)
    - test.sh
5. if using repo, copy pre commit script to `.git/hooks` directory
     cp pre-commit-hook.sh .git/hooks/pre-commit
     chmod +x .git/hooks/pre-commit
6. Try to commit and you should get TTY error
7. Switch git to `2.36.1` version (seems to be only possible by `brew 
extract`)
     brew tap-new --no-git $USER/local-tap
     brew extract --version=2.36.1 git $USER/local-tap
     brew install git@2.36.1
     brew link --overwrite git@2.36.1
8. Try committing again, TTY problem should be fixed
Let me know if you need more details etc.

Regards Piotrek

Next: René Scharfe
Message 1 of 6 in “Issue with git > 2.36.1 and pre-commit hook on macOS M1”
  1. PiotrekDec 11, 2022
  2. René ScharfeDec 12, 2022
  3. PiotrekDec 13, 2022
  4. René ScharfeDec 14, 2022
  5. PiotrekDec 17, 2022
  6. René ScharfeDec 17, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.