Skip to content

Fix stdin_has_data() #52

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions gitlint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import os
import platform
import select
import stat
import sys

import click
Expand Down Expand Up @@ -94,16 +94,12 @@ def build_config(ctx, target, config_path, c, extra_path, ignore, verbose, silen


def stdin_has_data():
""" Helper function that indicates whether the stdin has data incoming or not """
# This code was taken from:
# https://stackoverflow.com/questions/3762881/how-do-i-check-if-stdin-has-some-data

# Caveat, this probably doesn't work on Windows because the code is dependent on the unix SELECT syscall.
# Details: https://docs.python.org/2/library/select.html#select.select
# This isn't a real problem now, because gitlint as a whole doesn't support Windows (see #20).
# If we ever do, we probably want to fall back to the old detection mechanism of reading from the local git repo
# in case there's no TTY connected to STDIN.
return select.select([sys.stdin, ], [], [], 0.0)[0]
""" Helper function that indicates whether the stdin has data incoming or not

Read from stdin if that device is a pipe or a redirect.
"""
mode = os.fstat(sys.stdin.fileno()).st_mode
return stat.S_ISFIFO(mode) or stat.S_ISREG(mode)


@click.group(invoke_without_command=True, epilog="When no COMMAND is specified, gitlint defaults to 'gitlint lint'.")
Expand Down