diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-01-17 12:42:42 +0900 |
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-01-27 13:50:15 +0900 |
| commit | fda421a6f611bfed526f90d01e41271ba2aa33f3 (patch) | |
| tree | b3d3c8ff99d7d03ff076c58c011571f7a16d799b /code_format/server-side/srv_format_file | |
| parent | 0e60f5c6834eb89dec4c62ab67d0a08a87a2ba77 (diff) | |
| download | scripts-fda421a6f611bfed526f90d01e41271ba2aa33f3.tar.gz scripts-fda421a6f611bfed526f90d01e41271ba2aa33f3.zip | |
Code format: git update hook scriptcode-format/git-hook-update
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'code_format/server-side/srv_format_file')
| -rwxr-xr-x | code_format/server-side/srv_format_file | 37 |
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 |
