{"thread":{"id":"58931","subject":"Issue with git > 2.36.1 and pre-commit hook on macOS M1","startedAt":"2022-12-11T21:18:10Z","lastAt":"2022-12-17T08:34:36Z","messageCount":6,"participants":["Piotrek","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"468870","messageId":"51d5993f-a1e0-519e-ffa9-ec5205c5e96d@o2.pl","threadId":"58931","inReplyTo":null,"subject":"Issue with git > 2.36.1 and pre-commit hook on macOS M1","fromName":"Piotrek","fromEmail":"piotrekkr@o2.pl","sentAt":"2022-12-11T21:11:19Z","receivedAt":"2022-12-11T21:18:10Z","isPatch":false,"sender":{"key":"piotrekkr@o2.pl","avatar":null},"body":"Hello.\n\nOn MacOS 12.6.1 with M1 chip, git >=2.37.0 (installed by homebrew) and \npre-commit hook that is calling *make* target, that is calling *docker \ncompose run* command, we get error:\n\n     the input device is not a TTY\n\nAll works file with homebrew git version 2.36.1\n\n\n* DETAILS OF PROBLEM *\n\nThere is pre-commit hook in place that is using bash script to call \n`make` command which is in turn calling `docker compose run` to run some \ncheck before commit. After upgrading git version from `2.36.1` to \n`>=2.37` we constantly get error:\n\n > the input device is not a TTY\n\nExample pre-commit hook output:\n\n > docker compose run --rm --entrypoint \"\" app /code/test.sh\n > the input device is not a TTY\n > make: *** [Makefile:6: check] Error 1\n > !!! FAILING REGARDLESS OF CHECK RESULT !!!\n\n(the latest error message is just so we don't actually commit anything)\n\nAFAIK `docker compose` command is auto-detecting TTY because no `-t` or \n`-T` were set.\n\nBy doing some tests we managed to check that it is a problem with `git` \nversion.\n\nLatest version that it worked was `2.36.1`:\n\n > docker compose run --rm --entrypoint \"\" app /code/test.sh\n > =================== CHECK OK =================\n > !!! FAILING REGARDLESS OF CHECK RESULT !!!\n\nMachine and software we were testing on:\n\n > make --version\n > GNU Make 3.81\n >\n > docker compose version\n > Docker Compose version v2.12.2\n >\n > git --version\n > git version 2.38.1\n >\n > which git\n > /opt/homebrew/bin/git\n\nAlso, we tested with linux Ubuntu and all git versions are working fine \nwith same pre-commit hook. It seems related to `macOS` and `git` only.\n\n* REPLICATING THIS PROBLEM *\n\nEasiest way top replicate is to just clone sample repo I prepared here:\n\nhttps://github.com/piotrekkr/git-tty-issue-macos\n\nand go with replicate instructions from README.md.\n\nIf this is not okay then below I will copy and paste instruction with \nfile contents.\n\n\n* FILES *\n\n\n* Makefile *\n\n     COMPOSE_RUN = docker compose run --rm --entrypoint \"\"\n     check:\n     \t$(COMPOSE_RUN) app /code/test.sh\n\n\n\n* docker-compose.yml *\n\n     version: \"3.7\"\n     services:\n     app:\n         image: php:8.1.3-fpm-bullseye\n         volumes:\n         - \"${PWD}:/code\"\n         working_dir: /code\n\n\n* .git/hooks/pre-commit *\n\n     #!/usr/bin/env bash\n\n     make check\n\n     echo \"!!! FAILING REGARDLESS OF CHECK RESULT !!!\"\n     exit 1\n\n\n* test.sh *\n\n     #!/usr/bin/env bash\n\n     echo \"=================== CHECK OK =================\"\n\n\n(sorry for attaching like that, I'm not good with those plain text mail \nlists)\n\n* INSTRUCTIONS *\n\n1. have macOS with M1 chip (can be expensive)\n2. install `docker`, `docker compose v2`, `make`\n3. upgrade git with homebrew to version `>=2.37.0`\n4. clone repo or manually create files (in same directory)\n    - Makefile\n    - docker-compose.yml\n    - .git/hooks/pre-commit (with execute permissions)\n    - test.sh\n5. if using repo, copy pre commit script to `.git/hooks` directory\n\n     cp pre-commit-hook.sh .git/hooks/pre-commit\n     chmod +x .git/hooks/pre-commit\n\n6. Try to commit and you should get TTY error\n7. Switch git to `2.36.1` version (seems to be only possible by `brew \nextract`)\n\n     brew tap-new --no-git $USER/local-tap\n     brew extract --version=2.36.1 git $USER/local-tap\n     brew install git@2.36.1\n     brew link --overwrite git@2.36.1\n\n8. Try committing again, TTY problem should be fixed\n\n\nLet me know if you need more details etc.\n\nRegards\nPiotrek\n"},{"id":"468887","messageId":"30f80aa4-d5c1-4fce-f1c9-710eabeaa022@web.de","threadId":"58931","inReplyTo":"51d5993f-a1e0-519e-ffa9-ec5205c5e96d@o2.pl","subject":"Re: Issue with git > 2.36.1 and pre-commit hook on macOS M1","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2022-12-12T13:29:41Z","receivedAt":"2022-12-12T13:29:49Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 11.12.22 um 22:11 schrieb Piotrek:\n> Hello.\n>\n> On MacOS 12.6.1 with M1 chip, git >=2.37.0 (installed by homebrew)\n> and pre-commit hook that is calling *make* target, that is calling\n> *docker compose run* command, we get error:\n>\n> the input device is not a TTY\n>\n> All works file with homebrew git version 2.36.1\n\nBisects to a082345372 (hook API: fix v2.36.0 regression: hooks should be\nconnected to a TTY, 2022-06-07).\n\nAdding \"for fd in 0 1 2; do test -t $fd; printf %d $?; done; echo\" to\nthe shell script .git/hook/pre-commit yields 100 since a082345372, i.e.\nfd 1 (stdout) and fd 2 (stderr) are associated with a terminal, while\nfd 0 (stdin) is not.  Before we got 111, i.e. none of the standard file\ndescriptors were associated with a terminal.\n\nv2.37.0 includes a082345372.  v2.35.0 gives 100 as well, as expected, so\nolder versions of Git should have \"docker compose\" complain as well.\n\nWhile \"docker compose\" is right in that stdin is not a TTY, it never\nwas.  Redirecting the output its seems to help.  So I guess it checks if\nstdout is connected to a terminal and then expects stdin to be a TTY as\nwell.  Try appending \" | cat\" to the command in the pre-commit hook,\nwhich breaks the connection for stdout.\n\nRené\n"},{"id":"468998","messageId":"c07a5ac4-3da6-6fb4-4586-a83373bc05d4@o2.pl","threadId":"58931","inReplyTo":"30f80aa4-d5c1-4fce-f1c9-710eabeaa022@web.de","subject":"Re: Issue with git > 2.36.1 and pre-commit hook on macOS M1","fromName":"Piotrek","fromEmail":"piotrekkr@o2.pl","sentAt":"2022-12-13T21:02:46Z","receivedAt":"2022-12-13T21:02:57Z","isPatch":false,"sender":{"key":"piotrekkr@o2.pl","avatar":null},"body":"On 12.12.2022 14:29, René Scharfe wrote:\n\n> While \"docker compose\" is right in that stdin is not a TTY, it never\n> was.  Redirecting the output its seems to help.  So I guess it checks if\n> stdout is connected to a terminal and then expects stdin to be a TTY as\n> well.  Try appending \" | cat\" to the command in the pre-commit hook,\n> which breaks the connection for stdout.\n> \n> René\n\nJust to be sure if I understand this correctly. It is probably a bug in \ndocker compose expecting stdin to be a TTY, right? I'll write some bug \nreport to them, maybe they will take care of this since it is only on \nMacOS and all works fine with Linux.\n\nThank you for checking this René.\n"},{"id":"469047","messageId":"7054faf0-0f5b-e4a8-3166-bf715ed45a32@web.de","threadId":"58931","inReplyTo":"c07a5ac4-3da6-6fb4-4586-a83373bc05d4@o2.pl","subject":"Re: Issue with git > 2.36.1 and pre-commit hook on macOS M1","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2022-12-14T22:23:04Z","receivedAt":"2022-12-14T22:23:11Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 13.12.2022 um 22:02 schrieb Piotrek:\n> On 12.12.2022 14:29, René Scharfe wrote:\n>\n>> While \"docker compose\" is right in that stdin is not a TTY, it\n>> never was.  Redirecting the output its seems to help.  So I guess\n>> it checks if stdout is connected to a terminal and then expects\n>> stdin to be a TTY as well.  Try appending \" | cat\" to the command\n>> in the pre-commit hook, which breaks the connection for stdout.\n>>\n>> René\n>\n> Just to be sure if I understand this correctly. It is probably a bug\n> in docker compose expecting stdin to be a TTY, right? I'll write some\n> bug report to them, maybe they will take care of this since it is\n> only on MacOS and all works fine with Linux.\n\nI don't know \"docker compose\" well enough to say whether it's a bug,\nbut it seems it turns on some kind of terminal mode that needs both\nstdin and stdout to be connected to a TTY after only checking that one\nof them actually is.  Why not check both?\n\nCurious that only macOS should be affected.  Is stdin of a hook script a\nTTY on that platform?  Or can \"docker compose\" handle stdin not being a\nTTY and stdout being one there?\n\nRené\n"},{"id":"469203","messageId":"a1fb9d92-5161-5ba0-54f2-a03cbc45f399@o2.pl","threadId":"58931","inReplyTo":"7054faf0-0f5b-e4a8-3166-bf715ed45a32@web.de","subject":"Re: Issue with git > 2.36.1 and pre-commit hook on macOS M1","fromName":"Piotrek","fromEmail":"piotrekkr@o2.pl","sentAt":"2022-12-17T07:50:02Z","receivedAt":"2022-12-17T07:50:21Z","isPatch":false,"sender":{"key":"piotrekkr@o2.pl","avatar":null},"body":"On 14.12.2022 23:23, René Scharfe wrote:\n\n> I don't know \"docker compose\" well enough to say whether it's a bug,\n> but it seems it turns on some kind of terminal mode that needs both\n> stdin and stdout to be connected to a TTY after only checking that one\n> of them actually is.  Why not check both?\n> \n> Curious that only macOS should be affected.  Is stdin of a hook script a\n> TTY on that platform?  Or can \"docker compose\" handle stdin not being a\n> TTY and stdout being one there?\n> \n> René\n\nWell, seems like I somehow tested this wrong. Tried it again from \nscratch and on linux I also get this error. So this looks like not a \nbug. Docker compose CLI options page is a little confusing because of these:\n\n >--interactive , -i  true  Keep STDIN open even if not attached.\n >--no-TTY , -T \t     true  Disable pseudo-TTY allocation (default: \nauto-detected).\n >--tty , -t          true  Allocate a pseudo-TTY.\n\nSecond column with `true` values is titled `Default`, whatever it means.\nSo `--tty` and `--no-TTY` is set by default? Anyway, seems like it is \nchecking if at least one of stdout, stding, stderr is a tty and then \ntries to allocate a tty to all.\n\nYou can check docs here \nhttps://docs.docker.com/engine/reference/commandline/compose_run/#options\n\nAs a final solution I used makefile \"magic\" with `ifeq` and shell \ncommand like this:\n\n     $(shell test -t 0)\n     ifeq ($(.SHELLSTATUS), 1)\n     ALLOCATE_TTY = --no-TTY\n     endif\n\n     docker compose run $(ALLOCATE_TTY) --rm --entrypoint \"\" app \n/code/test.sh\n\n\nMaybe I'll just write to to them to clarify documentation on how those \nTTY options actually works by default.\n\nThanks for help with this.\nPiotr\n"},{"id":"469204","messageId":"18ad9fae-2afd-4315-c65f-d9bb92fa30fe@web.de","threadId":"58931","inReplyTo":"a1fb9d92-5161-5ba0-54f2-a03cbc45f399@o2.pl","subject":"Re: Issue with git > 2.36.1 and pre-commit hook on macOS M1","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2022-12-17T08:34:27Z","receivedAt":"2022-12-17T08:34:36Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 17.12.22 um 08:50 schrieb Piotrek:\n> On 14.12.2022 23:23, René Scharfe wrote:\n>\n>> Curious that only macOS should be affected.  Is stdin of a hook script a\n>> TTY on that platform?  Or can \"docker compose\" handle stdin not being a\n>> TTY and stdout being one there?\n\n> Well, seems like I somehow tested this wrong. Tried it again from\n> scratch and on linux I also get this error.\n\nAh, OK.\n\n> Docker compose CLI options page is a little confusing because of\n> these:\n>\n>>--interactive , -i  true  Keep STDIN open even if not attached.\n>>--no-TTY , -T          true  Disable pseudo-TTY allocation (default: auto-detected).\n>>--tty , -t          true  Allocate a pseudo-TTY.\n>\n> Second column with `true` values is titled `Default`, whatever it means.\n> So `--tty` and `--no-TTY` is set by default? Anyway, seems like it is\n> checking if at least one of stdout, stding, stderr is a tty and then\n> tries to allocate a tty to all.\n>\n> You can check docs here\n> https://docs.docker.com/engine/reference/commandline/compose_run/#options\nYeah, having the last two both on by default seems impossible.  Perhaps\nthe text in the parenthesis means that \"default\" is actually to detect\nTTYs automatically?  In any case the help text could be clearer.\n\n> As a final solution I used makefile \"magic\" with `ifeq` and shell command like this:\n>\n>     $(shell test -t 0)\n>     ifeq ($(.SHELLSTATUS), 1)\n>     ALLOCATE_TTY = --no-TTY\n>     endif\n>\n>     docker compose run $(ALLOCATE_TTY) --rm --entrypoint \"\" app /code/test.sh\n\nOK.  Would be nice if \"docker compose\" could handle that case\nautomatically, though, wouldn't it? :)\n\n> Maybe I'll just write to to them to clarify documentation on how\n> those TTY options actually works by default.\nGood idea.\n\nRené\n"}]}