summaryrefslogtreecommitdiff
path: root/abslibre/blacklist.git
diff options
context:
space:
mode:
authorParabola git <git@parabola.nu>2020-03-12 09:00:02 +0000
committerParabola git <git@parabola.nu>2020-03-12 09:00:02 +0000
commite54a6312fea82867900727abb332dde0bf293dec (patch)
treee17e7dbf94252d5e11945e0c08253519baf37395 /abslibre/blacklist.git
parent2bd54e10f3edcc9b2e8a7e259f65aab0ba9f5aa3 (diff)
Update from cron
Diffstat (limited to 'abslibre/blacklist.git')
-rwxr-xr-xabslibre/blacklist.git/hooks/pre-receive66
1 files changed, 66 insertions, 0 deletions
diff --git a/abslibre/blacklist.git/hooks/pre-receive b/abslibre/blacklist.git/hooks/pre-receive
new file mode 100755
index 0000000..509d3fa
--- /dev/null
+++ b/abslibre/blacklist.git/hooks/pre-receive
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# refs data via STDIN - one line per target ref (where ref_data is: prev_sha curr_sha ref_file)
+# e.g.
+# a559985626bbf4448ccf9041857449078db6d731 1d5002ade3f71200274f1ba39e35a732d86220b5 refs/heads/master
+# 0000000000000000000000000000000000000000 1d5002ade3f71200274f1ba39e35a732d86220b5 refs/heads/new-branch
+
+
+## constants ##
+
+readonly LOG_BLACKLIST_GIT_HOOK=1
+readonly LOG_DIR=/var/log/blacklist-validate
+readonly SHA_REGEX='^([0-9a-f]{40})$'
+
+
+## logging ##
+
+LogFile() # (ref)
+{
+ local ref=$1
+
+ echo ${LOG_DIR}/validate-${ref}
+}
+
+LogParseRefData() # (ref_data prev_sha curr_sha ref_file repo ref is_deletion)
+{
+ local ref_data=$1 ; local prev_sha=$2 ; local curr_sha=$3 ; local ref_file=$4 ;
+ local repo=$5 ; local ref=$6 ; local is_deletion=$7 ;
+ local log_file=$(LogFile ${repo} ${ref})
+
+ (( $LOG_BLACKLIST_GIT_HOOK )) && echo "ref_data=${ref_data}" > ${log_file} && \
+ echo "prev=${prev}" >> ${log_file} && \
+ echo "curr=${curr}" >> ${log_file} && \
+ echo "ref_file=${ref_file}" >> ${log_file} && \
+ echo "ref=${ref}" >> ${log_file} && \
+ echo "is_deletion=${is_deletion}" >> ${log_file}
+
+cat $log_file
+}
+
+
+## helpers ##
+
+ParseRefData() # (prev_sha curr_sha ref_file)
+{
+ local prev=$1
+ local curr=$2
+ local ref_file=$3
+ local ref=${ref_file##*/}
+ local repo=$(basename $(pwd))
+ local is_deletion=$(git show-ref "${ref}" > /dev/null && echo 0 || echo 1)
+
+LogParseRefData ${ref_data} ${prev_sha} ${curr_sha} ${ref_file} ${repo} ${ref} ${is_deletion}
+
+ # validate ref data
+ [[ "$#" == '3' ]] && \
+ [[ "${prev}" =~ ${SHA_REGEX} ]] && \
+ [[ "${curr}" =~ ${SHA_REGEX} ]] && \
+ [[ "${ref}" ]] || return
+}
+
+
+## main entry ##
+
+while read ref_data ; do "$(ParseRefData ${ref_data})" || exit 1 ; done ;
+exit 1