forked from franneck94/CppProjectTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
34 lines (25 loc) · 906 Bytes
/
Copy pathpre-commit
File metadata and controls
34 lines (25 loc) · 906 Bytes
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
#!/usr/bin/env sh
# Capture the list of staged files before running pre-commit hook
pre_commit_staged_files=$(git diff --cached --name-only)
# Run pre-commit hook
pre-commit
# Check the exit code of the pre-commit command
if [ $? -ne 0 ]; then
echo "pre-commit hook failed. Commit cancelled."
# Restage modified files that were previously staged before cancelling the commit
modified_files=$(git diff --cached --name-only | grep -F "$pre_commit_staged_files")
if [ -n "$modified_files" ]; then
git add $modified_files
fi
exit 1 # Exit with a non-zero code to cancel the commit
fi
# Run CMake tests using ctest
cd build
ctest --output-on-failure -j 12
# Check the exit code of ctest
if [ $? -ne 0 ]; then
echo "CTest failed. Commit cancelled."
exit 1 # Exit with a non-zero code to cancel the commit
fi
# If both pre-commit and CTest succeeded, the commit will proceed
exit 0