upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/git_hooks/commit-msg
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2023-09-01 00:00:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2023-09-13 09:24:49 +0000
commit6423baebd92e45c9be85157c443dff42e65d8d14 (patch)
tree6548edfd80d0cd9d1267378ebe816ec95e394137 /git_hooks/commit-msg
parent5c5feaa732363e32e2a980a887fa42b4394b1a5e (diff)
refactor: rebuild app skeleton
Create skeleton for a complete rebuild of the prototype as a production ready product. Includes design patterns for: - dependency injection - unit testing with dependency mocking - integration testing - error handling - config storage BREAKING-CHANGE: ground-up redesign with incompatible protocol standards
Diffstat (limited to 'git_hooks/commit-msg')
-rwxr-xr-xgit_hooks/commit-msg35
1 files changed, 35 insertions, 0 deletions
diff --git a/git_hooks/commit-msg b/git_hooks/commit-msg
new file mode 100755
index 0000000..e754e8d
--- /dev/null
+++ b/git_hooks/commit-msg
@@ -0,0 +1,35 @@
1#!/bin/sh
2### gitlint commit-msg hook start ###
3
4# Determine whether we have a tty available by trying to access it.
5# This allows us to deal with UI based gitclient's like Atlassian SourceTree.
6# NOTE: "exec < /dev/tty" sets stdin to the keyboard
7stdin_available=1
8(exec < /dev/tty) 2> /dev/null || stdin_available=0
9
10if [ $stdin_available -eq 1 ]; then
11 # Now that we know we have a functional tty, set stdin to it so we can ask the user questions :-)
12 exec < /dev/tty
13
14 # On Windows, we need to explicitly set our stdout to the tty to make terminal editing work (e.g. vim)
15 # See SO for windows detection in bash (slight modified to work on plain shell (not bash)):
16 # https://stackoverflow.com/questions/394230/how-to-detect-the-os-from-a-bash-script
17 if [ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "win32" ]; then
18 exec > /dev/tty
19 fi
20fi
21
22gitlint --staged --msg-filename "$1" run-hook
23exit_code=$?
24
25# If we fail to find the gitlint binary (command not found), let's retry by executing as a python module.
26# This is the case for Atlassian SourceTree, where $PATH deviates from the user's shell $PATH.
27if [ $exit_code -eq 127 ]; then
28 echo "Fallback to python module execution"
29 python -m gitlint.cli --staged --msg-filename "$1" run-hook
30 exit_code=$?
31fi
32
33exit $exit_code
34
35### gitlint commit-msg hook end ###