-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix stdin_has_data() #52
Conversation
When calling gitlint in a custom git commit hook on a gitlab server, stdin_has_data() will always return True regardless whether gitlint is called directly or text is piped into it. To reproduce you can call this script: import sys, stat, os if sys.stdin.isatty(): print("Input comes from tty.") else: print("Input doesn't come from tty.") mode = os.fstat(sys.stdin.fileno()).st_mode if stat.S_ISFIFO(mode): print("stdin is piped") elif stat.S_ISREG(mode): print("stdin is redirected") else: print("stdin is terminal") On my server it prints: Input doesn't come from tty. stdin is terminal stdin should only be read if the user uses a pipe or a redirect to pass data in.
I got similar feedback in #42 after I thought I fixed it with the last release. I need to make some more time to play with this, because this is a fundamental part of gitlint. I want to understand and test it properly myself before merging a PR related to it. I don't know when I have time, but I'm going to try and make some in the next few weeks since this is a fairly big issue. Appreciate your patience! I think the following should work as a temp workaround: |
My workaround is to use this patch. 😉 So there is no hurry on my side. Some test cases you can use:
|
BTW: The workaround you described @jorisroovers (piping the commit message body into |
As mentioned in #42, the "has-STDIN-data-check" doesn't work inside certain Jenkins and GitLab CI environments. |
@pbregener Have you tested my proposed patch? Can you comment how you configured GitLab CI? I am using this patch with GitLab. |
Yes. I am running |
v10.4.0 does not contain the proposed patch from this pull request. Can you apply the patch from this pull request and try again? How do you invoke gitlint? |
I applied the patch from this pull request to gitlint. I'm not sure what the gitlab-runner version has to do with this. I invoke gitlint from a bash script, which is linked in the project's |
You mentioned that you use it in GitLab with a commit hook which will be an entirely different thing. |
When calling gitlint in a custom git commit hook on a gitlab server, stdin_has_data() will always return True regardless whether gitlint is called directly or text is piped into it. To reproduce you can call this
script:
On my server it prints:
stdin should only be read if the user uses a pipe or a redirect to pass data in.