git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH] hooks: add some defaults to support sane workflow to pre-commit

From
Heiko Voigt <git-list@hvoigt.net>
Date
Feb 20, 2009, 18:13 UTC
Message-ID
<499EF2B6.7060103@hvoigt.net>

It sometimes happens that you move to a new machine and forget to setup your name and email address. To find this out after 10 commits can be quite frustrating.

As far as I know all "sane" workflows involve topic branches, so normally a developer will never commit directly on master but use topic branch instead and merge them into master once finished.

One thing which could be dangerous is if you clone a project containing submodules. If you would immediately start working in a submodule you would create commits with detached head. This can be a dangerous operation in terms of loosing commits and should be forbidden by default.

Signed-off-by: Heiko Voigt <git-list@hvoigt.net>
---
I also would like to vote for enabling some hooks by default. 
 templates/hooks--pre-commit.sample |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample
index 0e49279..6360da0 100755
--- a/templates/hooks--pre-commit.sample
+++ b/templates/hooks--pre-commit.sample
@@ -16,3 +16,26 @@ else
 fi
 
 exec git diff-index --check --cached $against --
+
+# check if username and email are setup
+if [ -z "$(git config --global user.name)" ]; then
+    echo "Please set your name and email address"
+    exit 1
+fi
+if [ -z "$(git config --global user.email)" ]; then
+    echo "Please set your name and email address"
+    exit 1
+fi
+
+# work should always be done on a feature branch
+if git branch | grep "^* master" > /dev/null; then
+    echo "No commits on master, please !"
+    exit 1
+fi
+
+# do not allow commits on detached head
+if git branch | grep "^* (no branch)" > /dev/null; then
+    echo "Commit on detached HEAD is dangerous !"
+    echo "Please checkout a branch first ..."
+    exit 1
+fi
-- 
1.6.1.2.390.gba743
Next: Wincent Colaiuta
Message 1 of 10 in “hooks: add some defaults to support sane workflow to pre-commit”
  1. hooks: add some defaults to support sane workflow to pre-commitHeiko Voigt, Feb 20, 2009
  2. Wincent ColaiutaFeb 20, 2009
  3. Heiko VoigtFeb 21, 2009
  4. Thomas RastFeb 21, 2009
  5. Heiko VoigtFeb 21, 2009
  6. Jakub NarebskiFeb 21, 2009
  7. Heiko VoigtFeb 21, 2009
  8. Heiko VoigtFeb 23, 2009
  9. Junio C HamanoOct 19, 2009
  10. Heiko VoigtOct 20, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.