Skip to content
Merged
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
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
cmake_minimum_required(VERSION 3.14)
project(LinuxCamPAM VERSION 0.9.7.1 LANGUAGES C CXX)

# --- Automatic Git Hook Installation ---
# Installs/Updates the pre-push hook to prevent accidental pushes to master
if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND EXISTS "${CMAKE_SOURCE_DIR}/scripts/hooks/pre-push")
message(STATUS "Installing git pre-push hook...")
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_SOURCE_DIR}/scripts/hooks/pre-push"
"${CMAKE_SOURCE_DIR}/.git/hooks/pre-push"
)
# Ensure it's executable
execute_process(
COMMAND chmod +x "${CMAKE_SOURCE_DIR}/.git/hooks/pre-push"
)
endif()

# --- Versioning with Git Hash ---
find_package(Git)
if(GIT_FOUND)
Expand Down
27 changes: 27 additions & 0 deletions scripts/hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Protected branch name
PROTECTED_BRANCH="master"

# Read stdin to determine what is being pushed
while read local_ref local_sha remote_ref remote_sha
do
# Check if we are pushing to the protected branch
if [[ "$remote_ref" == "refs/heads/$PROTECTED_BRANCH" ]]; then
echo "--------------------------------------------------"
echo "Build Safety: BLOCKED"
echo "--------------------------------------------------"
echo "You are trying to push directly to '$PROTECTED_BRANCH'."
echo "Direct pushes to this branch are prohibited to ensure code stability."
echo ""
echo "Please create a new branch and open a Pull Request:"
echo " git checkout -b feature/your-feature-name"
echo " git push -u origin feature/your-feature-name"
echo ""
echo "If you absolutely must push (Emergency), use: git push --no-verify"
echo "--------------------------------------------------"
exit 1
fi
done

exit 0