commit b8ff856fd83aa359283ade0421ebca6d79a069f0 Author: Balakrishnan Balasubramanian Date: Mon Feb 19 10:18:41 2024 -0500 initial version to check for staged changes diff --git a/pre-commit b/pre-commit new file mode 100755 index 0000000..9f3131c --- /dev/null +++ b/pre-commit @@ -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 diff --git a/pre-commit-staged-check.sh b/pre-commit-staged-check.sh new file mode 100755 index 0000000..a6b2760 --- /dev/null +++ b/pre-commit-staged-check.sh @@ -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