Skip to content

Commit

Permalink
Install pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mortinger91 committed Oct 24, 2023
1 parent bc694df commit 627cb06
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ProjectFolder/scripts/build_cmake_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ echo "Started building Debug CMake files..."
# Clearing build folder if it exists
rm -r build/debug &> /dev/null

echo "Installing pre-commit hook"
cp ./ProjectFolder/scripts/git_hooks/pre-commit ./.git/hooks/pre-commit

cmake -SProjectFolder --preset Debug -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang
RESULT=$?
echo "Finished building Debug CMake files!"
Expand Down
25 changes: 25 additions & 0 deletions ProjectFolder/scripts/git_hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Relative path to your custom script within your project folder
custom_script_path="./ProjectFolder/scripts/format.sh"

echo "pre-commit hook: Running ${custom_script_path}"

# Run the custom script
if [ -f "$custom_script_path" ]; then
# Navigate to the project root directory before running the script
project_root="$(git rev-parse --show-toplevel)"
cd "$project_root" || exit

# Run the custom script
sh "$custom_script_path"

# Check the exit status of the script
if [ $? -ne 0 ]; then
echo "Formatting script made changes. Re-stage modified files"
exit 1
fi
else
echo "${custom_script_path} not found. Commit aborted."
exit 1
fi

0 comments on commit 627cb06

Please sign in to comment.