diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-12-04 03:31:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-12-04 03:31:41 +0000 |
commit | 72b8c35be4293bd21de123854491c658c53af100 (patch) | |
tree | 735464cc081879561927a37650b1102beaa1f4f9 /gitlint-core/gitlint/files/commit-msg | |
parent | Adding upstream version 0.16.0. (diff) | |
download | gitlint-72b8c35be4293bd21de123854491c658c53af100.tar.xz gitlint-72b8c35be4293bd21de123854491c658c53af100.zip |
Adding upstream version 0.17.0.upstream/0.17.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gitlint-core/gitlint/files/commit-msg')
-rw-r--r-- | gitlint-core/gitlint/files/commit-msg | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gitlint-core/gitlint/files/commit-msg b/gitlint-core/gitlint/files/commit-msg new file mode 100644 index 0000000..e754e8d --- /dev/null +++ b/gitlint-core/gitlint/files/commit-msg @@ -0,0 +1,35 @@ +#!/bin/sh +### gitlint commit-msg hook start ### + +# Determine whether we have a tty available by trying to access it. +# This allows us to deal with UI based gitclient's like Atlassian SourceTree. +# NOTE: "exec < /dev/tty" sets stdin to the keyboard +stdin_available=1 +(exec < /dev/tty) 2> /dev/null || stdin_available=0 + +if [ $stdin_available -eq 1 ]; then + # Now that we know we have a functional tty, set stdin to it so we can ask the user questions :-) + exec < /dev/tty + + # On Windows, we need to explicitly set our stdout to the tty to make terminal editing work (e.g. vim) + # See SO for windows detection in bash (slight modified to work on plain shell (not bash)): + # https://stackoverflow.com/questions/394230/how-to-detect-the-os-from-a-bash-script + if [ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "win32" ]; then + exec > /dev/tty + fi +fi + +gitlint --staged --msg-filename "$1" run-hook +exit_code=$? + +# If we fail to find the gitlint binary (command not found), let's retry by executing as a python module. +# This is the case for Atlassian SourceTree, where $PATH deviates from the user's shell $PATH. +if [ $exit_code -eq 127 ]; then + echo "Fallback to python module execution" + python -m gitlint.cli --staged --msg-filename "$1" run-hook + exit_code=$? +fi + +exit $exit_code + +### gitlint commit-msg hook end ### |