From fda421a6f611bfed526f90d01e41271ba2aa33f3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 17 Jan 2024 12:42:42 +0900 Subject: Code format: git update hook script Signed-off-by: Michele Calgaro --- code_format/server-side/srv_format_file | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 code_format/server-side/srv_format_file (limited to 'code_format/server-side/srv_format_file') 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 -- cgit v1.2.3