New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tty settings for git hooks do not match git on other platforms #2914
Comments
We don't ship Python, so you're probably using a Python for Windows from python.org or the Microsoft app store. And that's likely the cause of your issue. You'll probably need to use MSYS2 Python to get the desired behaviour. If you use a MSYS2 Python you probably want to disable the python alias you likely have. |
surely you'll believe me if I use bash then: #!/usr/bin/env bash
[ -t 0 ] && echo 'stdin is' || echo 'stdin is not'
[ -t 1 ] && echo 'stdout is' || echo 'stdout is not'
[ -t 2 ] && echo 'stderr is' || echo 'stderr is not'
exit 1 > git commit -m wat --allow-empty
stdin is not
stdout is not
stderr is |
Interesting. First of all, that your idea was probably to ask This is the correct call to make on Linux, macOS and other Unix-y systems. However, on Windows, the semantics are slightly different. Just enough to confuse you:
Note how it talks about a character device? Win32 Consoles are character devices, but so is And Therefore, opening Since Python (I assume you mean the version that can be installed via the Windows Store) seems to simply pass through to the
I actually see vastly different behavior in Git Bash than in Git CMD. In the following table,
As you can see, the So what about that Alas, hooks are executed with their Further, I guess that the MSYS2 Bash tries a little harder and still figures out that the duplicated handle redirects to an interactive console. Hence the difference in the This is only a guess at this point, though, but I already spent more than half an hour to write up this explanation and need to go back to taking care of more pressing things. @asottile maybe you can continue the investigation at this point? |
Maybe you need to do something more along the lines of calling |
I'm actually using the python.org installers, the windows store ones are fraught with weird behaviours / edge cases that I'd rather not deal with until they get ironed out there I still think there is a problem with git as redirection in cmd works correctly: > python -c "import sys; print(sys.stdout.isatty()); print(sys.stderr.isatty())"
True
True
> python -c "import sys; print(sys.stdout.isatty()); print(sys.stderr.isatty())" 1>&2
True
True
> python -c "import sys; print(sys.stdout.isatty()); print(sys.stderr.isatty())" 2>&1
True
True |
This comment has been minimized.
This comment has been minimized.
@asottile and those installers would be where? I hoped that my comment would inspire you a bit more to imitate the verbosity and to continue the investigation. |
Ah, sorry I assumed clicking downloads on python.org would be obvious, my bad! Here's the link to 3.9.0: https://www.python.org/downloads/release/python-390/ I'm using the |
Okay. I still consider the remainder of the investigation in your court. |
@dscho what more would you like me to show you, normal process redirection works for cmd and |
What more would you like to have explained? I laid out why |
as far as I understand from your explanation git-for-windows's method of redirection is incorrect which breaks isatty -- and that's the bug that needs fixing to resolve this issue |
@dscho I'm not sure how we got off on the wrong foot but I'm trying to understand your perspective -- do you not think this is a bug? what part of this makes it not a bug -- there's a very clear behaviour difference between the platforms and even between normal executables on the same platform and in every comparison git-for-windows is the odd one out -- and again in case it isn't clear, I don't particularly care about the As a maintainer myself I completely understand the want to strive for simplicity and prioritize the important things, but I can't for the life of me see why you're being so dismissive for something that (to me) is very clearly a bug. I want to understand better your attitude so I can work with you instead of against you as it seems is happening right now I think it's fair to say that you're not being a very empathetic maintainer and at best you're being dismissive and at worst you're being unwelcoming and directly disrespectful. We all want to make the software better for everyone and the way you're treating a newcomer to your project seems very bad. |
Closing as stale. |
this isn't stale -- it's still broken -- please reopen thanks! |
@asottile I see that you offered objections that my explanation somehow does not explain the discrepancy between CMD and MinTTY. But it does. In MinTTY, there is no Win32 Console to play with. Not unless you use |
no that doesn't explain why stderr behaves correctly and stdout does not |
Setup
defaults?
to the issue you're seeing?
pretty bog standard, I've seen this on other installations on other machines as well
Details
Git Bash + cmd.exe both exhibit the same behaviour
Minimal, Complete, and Verifiable example
this will help us understand the issue.
.git/hooks/pre-commit
with these contents (may needpython3
on posix)chmod +x .git/hooks/pre-commit
git commit --allow-empty -m foo
Here's the output on posix:
Here's the output on windows:
URL to that repository to help us with testing?
N/A (a blank repository reproduces)
background on why this matters: I'm using the tty attribute of stdout to determine if I should produce ansi color escape sequences
I don't particularly care about the incorrect (?) stdin being a tty, I'm more concerned about stdout being correct
The text was updated successfully, but these errors were encountered: