File: pre-commit.hook

package info (click to toggle)
nextcloud-spreed-signaling 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,620 kB
  • sloc: sh: 447; makefile: 187; python: 78
file content (29 lines) | stat: -rwxr-xr-x 1,494 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
#
# Check that Go files have been formatted
#

for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.go$"` ; do
    echo "Checking ${file} ..."
    # nf is the temporary checkout. This makes sure we check against the
    # revision in the index (and not the checked out version).
    nf=`git checkout-index --temp "${file}" | cut -f 1`
    newfile=`mktemp "/tmp/${nf}.XXXXXX"` || exit 1
    gofmt ${nf} > "${newfile}" 2>> /dev/null
    diff -u -p "${nf}" "${newfile}"
    r=$?
    rm "${newfile}"
    rm "${nf}"
    if [ $r != 0 ] ; then
echo "================================================================================================="
echo " Code format error in: $file                                                                      "
echo "                                                                                                 "
echo " Please fix before committing. Don't forget to run git add before trying to commit again.        "
echo " If the whole file is to be committed, this should work (run from the top-level directory):      "
echo "                                                                                                 "
echo "   go fmt $file; git add $file; git commit"
echo "                                                                                                 "
echo "================================================================================================="
        exit 1
    fi
done