diff options
Diffstat (limited to 'gitlint/files')
-rw-r--r-- | gitlint/files/commit-msg | 78 | ||||
-rw-r--r-- | gitlint/files/gitlint | 25 |
2 files changed, 35 insertions, 68 deletions
diff --git a/gitlint/files/commit-msg b/gitlint/files/commit-msg index e468290..6a25d34 100644 --- a/gitlint/files/commit-msg +++ b/gitlint/files/commit-msg @@ -8,74 +8,28 @@ stdin_available=1 (exec < /dev/tty) 2> /dev/null || stdin_available=0 if [ $stdin_available -eq 1 ]; then - # Set bash color codes in case we have a tty - RED="\033[31m" - YELLOW="\033[33m" - GREEN="\033[32m" - END_COLOR="\033[0m" - # Now that we know we have a functional tty, set stdin to it so we can ask the user questions :-) exec < /dev/tty -else - # Unset bash colors if we don't have a tty - RED="" - YELLOW="" - GREEN="" - END_COLOR="" -fi -run_gitlint(){ - echo "gitlint: checking commit message..." - python -m gitlint.cli --staged --msg-filename "$1" - gitlint_exit_code=$? -} - -# Prompts a given yes/no question. -# Returns 0 if user answers yes, 1 if no -# Reprompts if different answer -ask_yes_no_edit(){ - ask_yes_no_edit_result="no" - # If we don't have a stdin available, then just return "No". - if [ $stdin_available -eq 0 ]; then - ask_yes_no_edit_result="no" - return; + # On Windows, we need to explicitely 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 - # Otherwise, ask the question until the user answers yes or no - question="$1" - while true; do - read -p "$question" yn - case $yn in - [Yy]* ) ask_yes_no_edit_result="yes"; return;; - [Nn]* ) ask_yes_no_edit_result="no"; return;; - [Ee]* ) ask_yes_no_edit_result="edit"; return;; - esac - done -} - -run_gitlint "$1" +fi -while [ $gitlint_exit_code -gt 0 ]; do - echo "-----------------------------------------------" - echo "gitlint: ${RED}Your commit message contains the above violations.${END_COLOR}" - ask_yes_no_edit "Continue with commit anyways (this keeps the current commit message)? [y(es)/n(no)/e(dit)] " - if [ $ask_yes_no_edit_result = "yes" ]; then - exit 0 - elif [ $ask_yes_no_edit_result = "edit" ]; then - EDITOR=${EDITOR:-vim} - $EDITOR "$1" - run_gitlint "$1" - else - echo "Commit aborted." - echo "Your commit message: " - echo "-----------------------------------------------" - cat "$1" - echo "-----------------------------------------------" +gitlint --staged --msg-filename "$1" run-hook +exit_code=$? - exit $gitlint_exit_code - fi -done +# 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 -echo "gitlint: ${GREEN}OK${END_COLOR} (no violations in commit message)" -exit 0 +exit $exit_code ### gitlint commit-msg hook end ### diff --git a/gitlint/files/gitlint b/gitlint/files/gitlint index 15a6626..e95bf9e 100644 --- a/gitlint/files/gitlint +++ b/gitlint/files/gitlint @@ -4,7 +4,7 @@ # one rule and each key in it is an option for that specific rule. # # Rules and sections can be referenced by their full name or by id. For example -# section "[body-max-line-length]" could be written as "[B1]". Full section names are +# section "[body-max-line-length]" could also be written as "[B1]". Full section names are # used in here for clarity. # # [general] @@ -43,6 +43,11 @@ # [title-max-length] # line-length=50 +# Conversely, you can also enforce minimal length of a title with the +# "title-min-length" rule: +# [title-min-length] +# min-length=5 + # [title-must-not-contain-word] # Comma-separated list of words that should not occur in the title. Matching is case # insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING" @@ -50,8 +55,7 @@ # words=wip # [title-match-regex] -# python like regex (https://docs.python.org/2/library/re.html) that the -# commit-msg title must be matched to. +# python-style regex that the commit-msg title must match # Note that the regex can contradict with other rules if not used correctly # (e.g. title-must-not-contain-word). # regex=^US[0-9]* @@ -74,9 +78,13 @@ # it in the commit message. # files=gitlint/rules.py,README.md +# [body-match-regex] +# python-style regex that the commit-msg body must match. +# E.g. body must end in My-Commit-Tag: foo +# regex=My-Commit-Tag: foo$ + # [author-valid-email] -# python like regex (https://docs.python.org/2/library/re.html) that the -# commit author email address should be matched to +# python-style regex that the commit author email address must match. # For example, use the following regex if you only want to allow email addresses from foo.com # regex=[^@]+@foo.com @@ -98,9 +106,14 @@ # Use 'all' to ignore all rules # ignore=T1,body-min-length +# [ignore-body-lines] +# Ignore certain lines in a commit body that match a regex. +# E.g. Ignore all lines that start with 'Co-Authored-By' +# regex=^Co-Authored-By + # This is a contrib rule - a community contributed rule. These are disabled by default. # You need to explicitly enable them one-by-one by adding them to the "contrib" option # under [general] section above. # [contrib-title-conventional-commits] # Specify allowed commit types. For details see: https://www.conventionalcommits.org/ -# types = bugfix,user-story,epic
\ No newline at end of file +# types = bugfix,user-story,epic |