File: format-source.sh

package info (click to toggle)
snapd-glib 1.70-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,452 kB
  • sloc: ansic: 30,379; cpp: 15,591; makefile: 62; sh: 31
file content (36 lines) | stat: -rwxr-xr-x 915 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

SOURCE_FILES="snapd-glib/*.[ch] snapd-glib/requests/*.[ch] snapd-qt/*.cpp snapd-qt/*.h snapd-qt/Snapd/*.h tests/*.[ch] tests/*.cpp"

if [[ "$1" == "pre-commit" ]]; then
    echo Checking source style
    PRE_COMMIT=1
else
    PRE_COMMIT=0
fi

passed=true
for file in $SOURCE_FILES; do
    if [ $# -eq 0 ]; then
        # no parameters? Just apply the changes
        echo Formating $file
        clang-format -i $file
    else
        # any parameter? check that the formatting is fine
        clang-format $file > $file.formatted
        echo Checking $file
        if [ $PRE_COMMIT -eq 0 ]; then
            diff $file $file.formatted
        else
            diff $file $file.formatted > /dev/null
        fi
        if [ $? != 0 ]; then
            passed=false
        fi
        rm $file.formatted
    fi
done
if [ $passed = false ]; then
    echo Failed to pass clang-format check
    exit 1
fi