]> gitweb.fluxo.info Git - utils-git.git/commitdiff
Avoid detached HEAD
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 18 Nov 2017 08:26:43 +0000 (06:26 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 18 Nov 2017 08:26:43 +0000 (06:26 -0200)
commit

diff --git a/commit b/commit
index f1396508282c6493866c75b618289931ac4b0b20..0bf2b18696679e580b59ff3fb00cf6913a4fcb97 100755 (executable)
--- 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