Browse code

Add implementation

Robert Cranston authored on 25/04/2020 14:27:05
Showing 2 changed files

... ...
@@ -2,7 +2,13 @@
2 2
 
3 3
 A [Git hook][githooks] that prevents you from committing unintended content.
4 4
 
5
+`git-hook-nocommit` is intended to be used as a [pre-commit][] hook and will
6
+refuse to commit any files with content that matches (case insensitively) the
7
+extended regex `$GIT_HOOK_NOCOMMIT_REGEX` (or `nocommit|nocheckin` if it is
8
+empty) unless `$GIT_HOOK_NOCOMMIT_DISABLE` is non-empty.
9
+
5 10
 [githooks]: https://git-scm.com/docs/githooks
11
+[pre-commit]: https://git-scm.com/docs/githooks#_pre_commit
6 12
 
7 13
 ## License
8 14
 
9 15
new file mode 100755
... ...
@@ -0,0 +1,12 @@
1
+#!/bin/sh
2
+set -euC
3
+
4
+regex=${GIT_HOOK_NOCHECKIN_REGEX:="nocommit|nocheckin"}
5
+
6
+# Redirect output to stderr.
7
+exec 1>&2
8
+
9
+if [ -z "${GIT_HOOK_NOCHECKIN_DISABLE:-}" ]
10
+then
11
+    ! git grep --cached --ignore-case --line-number --extended-regexp "$regex"
12
+fi