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

Stop a git commit by a specific author using pre-commit hook

From
ACAdrian Cornish <git@bluedreamer.com>
Date
Mar 9, 2012, 01:15 UTC
Message-ID
<CAGc=MuCQoQ711uXnB8J80RqsY+pqbaeCOXHjy0-mjq7a_ESdyA@mail.gmail.com>
Hi All,

My plan is to use git to keep track of changes in /etc but when committing I want to have the person making the change specify themselves as author by adding the --author option on the commandline.

So I would like to stop accidental commits as root.

I tried creating this pre-commit hook but it is not working - git var is still returning root even if I specify the author on commit line.

TIA Adrian

AUTHOR=`git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p'`
if [ "$AUTHOR" == "root <root@localhost>" ];
then
   echo "Please commit under your own user name instead of \"$AUTHOR\":"
   echo 'git commit --author="Adrian"'
   echo "or if your name is not already in logs use full ident"
   echo 'git commit --author="Adrian Cornish <a@localhost>"'
   exit 1
fi
exit 0
Next: Neal Kreitzinger
Message 1 of 13 in “Stop a git commit by a specific author using pre-commit hook”
  1. Adrian CornishMar 9, 2012
  2. Neal KreitzingerMar 10, 2012
  3. Junio C HamanoMar 10, 2012
  4. Neal KreitzingerMar 10, 2012
  5. Junio C HamanoMar 11, 2012
  6. 3/4 test: does pre-commit-hook learn authorship?Junio C Hamano, Mar 11, 2012
  7. Johannes SixtMar 11, 2012
  8. Junio C HamanoMar 11, 2012
  9. 3/4 ident.c: add split_ident_line() to parse formatted ident lineJunio C Hamano, Mar 11, 2012
  10. 3/3 commit: pass author/committer info to hooksJunio C Hamano, Mar 11, 2012
  11. Jeff KingMar 12, 2012
  12. 3/4 run_hook(): enhance the interface to pass arbitrary environmentJunio C Hamano, Mar 11, 2012
  13. 4/4 commit: pass author/committer info to hooksJunio C Hamano, Mar 11, 2012

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.