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

[PATCH] pre-commit.sample: don't print incidental SHA1

From
Jim Meyering <jim@meyering.net>
Date
May 16, 2009, 10:21 UTC
Message-ID
<87y6sx1h6p.fsf@meyering.net>

Make the sample pre-commit hook script discard all git-rev-parse output, not just stderr. Otherwise, it would print an SHA1.

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
[this patch applies at least to "next"]
I enabled the sample pre-commit hook and was surprised to
see new output with every commit.  It was due to that script's
use of git-rev-parse.

Also, I noticed the use of "git-hyphen" git-rev-parse. Perhaps that hyphen has been left in deliberately, for portability to very old versions of git?

While the 800+ uses of "git rev-parse" far outnumber uses of the two-hyphen version, this is far from being the only use in code (this is on the "next" branch):

  $ git grep -l git-rev-parse|grep -vE 'Docu|command-list|\.giti'
  contrib/emacs/git.el
  contrib/examples/git-revert.sh
  git-archimport.perl
  git-cvsexportcommit.perl
  git-cvsimport.perl
  git-submodule.sh
  gitweb/gitweb.perl
  perl/Git.pm
  templates/hooks--pre-commit.sample
 templates/hooks--pre-commit.sample |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample
index 0e49279..0ba6207 100755
--- a/templates/hooks--pre-commit.sample
+++ b/templates/hooks--pre-commit.sample
@@ -7,7 +7,7 @@
 #
 # To enable this hook, rename this file to "pre-commit".

-if git-rev-parse --verify HEAD 2>/dev/null
+if git-rev-parse --verify HEAD >/dev/null 2>&1
 then
 	against=HEAD
 else
-- 
1.6.3.1.83.g37eb7
Next: Junio C Hamano
Message 1 of 2 in “pre-commit.sample: don't print incidental SHA1”
  1. pre-commit.sample: don't print incidental SHA1Jim Meyering, May 16, 2009
  2. Junio C HamanoMay 16, 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.