initial version to check for staged changes

This commit is contained in:
Balakrishnan Balasubramanian 2024-02-19 10:18:41 -05:00
commit b8ff856fd8
2 changed files with 33 additions and 0 deletions

19
pre-commit Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
set -eu
# This also works
# $(git rev-parse --show-toplevel)/.git/hooks/pre-commit.sample
sample_hook="${PWD%"$GIT_PREFIX"}"/.git/hooks/pre-commit.sample
if test -x "$sample_hook"
then
$sample_hook
fi
current_dir=$(dirname "$0")
"$current_dir"/pre-commit-staged-check.sh
# vim: set ft=sh

14
pre-commit-staged-check.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
case $GIT_INDEX_FILE in
*.lock)
if GIT_INDEX_FILE=${GIT_INDEX_FILE%.lock} git status --porcelain | grep '^M'
then
echo "Error: Found both staged and unstaged changes when trying to commit with 'git commit -a'."
echo "Do two seperate commits with, 'git commit -m ...' and 'git commit -a -m ...'"
echo "Or 'git reset .' and then 'git commit -a -m ...' for a single commit"
exit 1
fi
;;
esac