You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scripts/code_format/server-side/srv_format_file

38 lines
854 B
Bash

#!/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