File: pre-commit

package info (click to toggle)
libyami 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,152 kB
  • sloc: cpp: 44,247; ansic: 1,255; makefile: 728; lisp: 479; sh: 21; python: 19
file content (31 lines) | stat: -rwxr-xr-x 1,312 bytes parent folder | download | duplicates (3)
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
## strip trailing whitespace
for file in `git diff --check --cached | grep '^[^+-]' | grep -o '^.*[0-9]\+:'` ; do
    file_name=`echo ${file} | grep -o '^[^:]\+'`
    line_number=`echo ${file} | grep -oP '(?<=:)[0-9]+(?=:)'`
    # I think the reason there are two sed commands here
    # is that 'sed -i' is different on different systems.
    # shoot me.
    (sed -i "${line_number}s/\s*$//" "${file_name}" > /dev/null 2>&1 \
        || sed -i '' -E "${line_number}s/\s*$//" "${file_name}")
    git add ${file_name}
    echo "Re-wrote ${file_name} to trim whitespace."
done

## remove 'x' bit and apply kr style for source file
for file in `git diff --cached  --name-only`; do
    filename=$(basename "$file")
    extension="${filename##*.}"
    dir_name=$(dirname "$file")
    if test "$extension" = "h" || test "$extension" = "c" || test "$extension" = "cpp"; then
        # remove the 'x' bit for files
        echo "remove 'x' for ${file}"
        chmod -x ${file}
    fi
done

echo "****************************************************"
echo "* applying coding style to the changed files, you can:"
echo "*     a) [check ] it by 'git diff'"
echo "*     b) [accept] it by 'git commit -a --amend'"
echo "*     c) [reject] it by 'git reset --hard'"
echo "****************************************************"