Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# are installed, and if so, uses the installed version to format
# the staged changes.

base=clang-format-3.8
base=/opt/rocm/hcc/bin/clang-format
format=""

# Redirect output to stderr.
Expand All @@ -16,8 +16,8 @@ type "$base" >/dev/null 2>&1 && format="$base"
# no versions of clang-format are installed
if [ -z "$format" ]
then
echo "$base is not installed. Commit is cancelled. Delete the hook to force commit."
exit 1
echo "$base is not installed. Pre-commit hook will not be executed."
exit 0
fi

# Do everything from top - level
Expand All @@ -31,28 +31,13 @@ else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

exitCode=0

# do the formatting
for file in $(git diff-index --cached --name-only $against | grep -E '\.h$|\.hpp$|\.cpp$|\.cl$|\.h\.in$|\.hpp\.in$|\.cpp\.in$')
do
if [ -e "$file" ]
then
# echo "$format $file"
"$format" -style=file -output-replacements-xml "$file" | grep "\<replacement\>" >/dev/null
if [ $? -ne 1 ]; then
echo "$format" -i -style=file "$file"
exitCode=1
fi

echo "$format $file"
"$format" -i -style=file "$file"
fi
done

if [ $exitCode -eq 1 ]; then
echo "Please fix the errors by running the commands listed above."
echo "Commit is cancelled. You may force by deleting the hook in .githook"
else
echo "Clang format checks passed"
fi

exit $exitCode
Loading