From 8b56dface439ff13c9977d958b891bfb79b09850 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 18 Nov 2017 06:26:43 -0200 Subject: Avoid detached HEAD --- commit | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/commit b/commit index f139650..0bf2b18 100755 --- a/commit +++ b/commit @@ -131,6 +131,12 @@ function git_commit { # Remove '--config' from args, otherwise it goes to the commit log params="`echo $* | sed -e 's/--config//'`" + # Avoid detached HEAD + if $GIT branch | grep -q '^* (HEAD detached'; then + echo "Beware: trying to commit in detached HEAD state; checkout to a branch first" + exit 1 + fi + # If there are no staged files, commit everything. # Otherwise commit just what was staged if $GIT status --short | grep -q "^[AM]"; then -- cgit v1.2.3