summaryrefslogtreecommitdiffstats
path: root/code_format/server-side
diff options
context:
space:
mode:
Diffstat (limited to 'code_format/server-side')
-rwxr-xr-xcode_format/server-side/srv_format_file37
1 files changed, 37 insertions, 0 deletions
diff --git a/code_format/server-side/srv_format_file b/code_format/server-side/srv_format_file
new file mode 100755
index 0000000..e201ffb
--- /dev/null
+++ b/code_format/server-side/srv_format_file
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+#
+# This script is intended to run on the gitea server from the git update script.
+# It will extract the required file from the commit hash and filename, then
+# invoke the 'uncrustify_file.sh' script to verify if the file meets the required
+# code format.
+#
+# Parameters:
+# $1: config file
+# $2: commit hash
+# $3: file to verify
+#
+
+SCRIPT_DIR=`dirname $(readlink -f "$0")`
+
+CODE_FORMAT_DIR="/tmp/code-format/"
+[ -d "${CODE_FORMAT_DIR}" ] || mkdir "${CODE_FORMAT_DIR}"
+
+TMP_SRC_FILE=`mktemp -p ${CODE_FORMAT_DIR} "tmp_XXXXXXXX_${3##*/}"`
+
+# Helper function to clean up the temp file on exit
+function do_exit()
+{
+ [ ! -e "$TMP_SRC_FILE" ] || rm "$TMP_SRC_FILE"
+ exit $1
+}
+
+# Get the file to verify
+git show $2:$3 >$TMP_SRC_FILE
+
+${SCRIPT_DIR}/../uncrustify_file "$1" "${TMP_SRC_FILE}" 0
+if [ $? -eq 0 ]; then
+ do_exit 0
+else
+ do_exit 1
+fi