File: pre-commit

package info (click to toggle)
libkysdk-applications 3.0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 7,384 kB
  • sloc: cpp: 53,566; xml: 1,865; ansic: 272; sh: 35; makefile: 6
file content (14 lines) | stat: -rw-r--r-- 646 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

# This script is used to format the code using clang-format before git commit.

readonly output=$(git clang-format --extensions 'cpp,h,hpp,c' -v --diff)

if [[ "$output" == *"no modified files to format"* ]]; then exit 0; fi
if [[ "$output" == *"clang-format did not modify any files"* ]]; then exit 0; fi

echo "ERROR: You have unformatted changes, please format your files. You can do this using the following commands:"
echo "       git clang-format --extensions 'cpp,h,hpp,c' --force # format the changed parts"
echo "       git clang-format --extensions 'cpp,h,hpp,c' --diff # preview the changes done by the formatter"
exit 1