summaryrefslogtreecommitdiffstats
path: root/code_format/server-side/srv_format_file
blob: e201ffbe3ccc09db16d803618a3e166dc73aded9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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