xref: /OK3568_Linux_fs/external/mpp/tools/hooks/pre-commit (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun
3*4882a593Smuzhiyunout_file="./fmt_df.txt"
4*4882a593Smuzhiyuncur_dir=$(pwd)
5*4882a593Smuzhiyunscript_dir=tools/
6*4882a593Smuzhiyun
7*4882a593Smuzhiyunecho "[git-hook]: before commit, format code use mpp_astyle.sh ..."
8*4882a593Smuzhiyun
9*4882a593Smuzhiyuncd $script_dir
10*4882a593Smuzhiyun./mpp_astyle.sh
11*4882a593Smuzhiyun
12*4882a593Smuzhiyuncd $cur_dir
13*4882a593Smuzhiyun
14*4882a593Smuzhiyungit status -s | grep "^MM " > $out_file
15*4882a593Smuzhiyun
16*4882a593Smuzhiyunif [ -s $out_file ]
17*4882a593Smuzhiyunthen {
18*4882a593Smuzhiyun    echo "[git-hook]: code changed after formating, please commit again."
19*4882a593Smuzhiyun    rm $out_file
20*4882a593Smuzhiyun    echo "[git-hook]: git status below:"
21*4882a593Smuzhiyun    git status
22*4882a593Smuzhiyun    exit 1
23*4882a593Smuzhiyun} else {
24*4882a593Smuzhiyun    echo "[git-hook]: nothing change after formating, commit continues."
25*4882a593Smuzhiyun    if [ -f $out_file ]
26*4882a593Smuzhiyun    then {
27*4882a593Smuzhiyun        rm $out_file
28*4882a593Smuzhiyun    } fi
29*4882a593Smuzhiyun    exit 0
30*4882a593Smuzhiyun} fi
31*4882a593Smuzhiyun
32