From 8c1e48eb20a896e3ced5fd1dfccd98aa168b3d60 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Sat, 8 Nov 2025 21:09:19 +0100 Subject: [PATCH] feat(git): add confirm prompt before commit to master branch (#65) Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/65 --- .gitconfig | 2 ++ .gitignore | 2 ++ .local/bin/git-hooks/pre-commit | 14 ++++++++++++++ Makefile | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .local/bin/git-hooks/pre-commit diff --git a/.gitconfig b/.gitconfig index aa7de55..1046f38 100644 --- a/.gitconfig +++ b/.gitconfig @@ -18,3 +18,5 @@ [commit] gpgsign = true verbose = true +[init] + templatedir = ~/.local/bin/git-hooks diff --git a/.gitignore b/.gitignore index f296ae8..164c256 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ !.bash_aliases !.bash_profile !.local/bin/ +!.local/bin/git-hooks/ +!.local/bin/git-hooks/pre-commit !.local/bin/code_server_export_extensions !.local/share/ !.local/share/code-server/ diff --git a/.local/bin/git-hooks/pre-commit b/.local/bin/git-hooks/pre-commit new file mode 100644 index 0000000..064ece3 --- /dev/null +++ b/.local/bin/git-hooks/pre-commit @@ -0,0 +1,14 @@ +#!/bin/bash + +# Get the current branch name +current_branch=$(git rev-parse --abbrev-ref HEAD) + +# Check if the current branch is master +if [[ "$current_branch" == "master" ]]; then + read -p "You are about to commit to the master branch. Do you want to continue? (y/n) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Commit aborted." + exit 1 + fi +fi \ No newline at end of file diff --git a/Makefile b/Makefile index 5a3240a..51e3ee9 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ dotfiles: # Use tracked git hooks git-hooks: - git config --local core.hooksPath .local/share/git/hooks + git config --global core.hooksPath .local/bin/git-hooks # Export code-server extensions to config directory code-extensions: