forked from intel/libyami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·31 lines (29 loc) · 1.28 KB
/
pre-commit
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 "****************************************************"