git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] hooks: add some defaults to support sane workflow to pre-commit
@ 2009-02-20 18:13 Heiko Voigt
  2009-02-20 20:49 ` Wincent Colaiuta
  2009-10-19  8:50 ` Junio C Hamano
  0 siblings, 2 replies; 10+ messages in thread
From: Heiko Voigt @ 2009-02-20 18:13 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-10-20 19:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-20 18:13 [RFC PATCH] hooks: add some defaults to support sane workflow to pre-commit Heiko Voigt
2009-02-20 20:49 ` Wincent Colaiuta
2009-02-21 10:56   ` Heiko Voigt
2009-02-21 11:16     ` Thomas Rast
2009-02-21 13:31       ` Heiko Voigt
2009-02-21 14:05         ` Jakub Narebski
2009-02-21 14:30           ` Heiko Voigt
2009-02-23 18:41         ` Heiko Voigt
2009-10-19  8:50 ` Junio C Hamano
2009-10-20 19:59   ` Heiko Voigt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).