public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Heiko Voigt <git-list@hvoigt•net>
To: git@vger•kernel.org
Subject: [RFC PATCH] hooks: add some defaults to support sane workflow to pre-commit
Date: Fri, 20 Feb 2009 19:13:10 +0100	[thread overview]
Message-ID: <499EF2B6.7060103@hvoigt.net> (raw)

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

             reply	other threads:[~2009-02-20 18:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-20 18:13 Heiko Voigt [this message]
2009-02-20 20:49 ` [RFC PATCH] hooks: add some defaults to support sane workflow to pre-commit 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=499EF2B6.7060103@hvoigt.net \
    --to=git-list@hvoigt$(echo .)net \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox