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

[PATCH 3/4] hooks--pre-push.sample: use hash-agnostic null OID

From
Denton Liu <liu.denton@gmail.com>
Date
Sep 18, 2020, 11:19 UTC
Message-ID
<9d6c2951ab0a2c2e92353c238b008538fe6a6327.1600427894.git.liu.denton@gmail.com>
In-Reply-To
<cover.1600427894.git.liu.denton@gmail.com>

The pre-push sample hook has the null OID hardcoded as 40 zeros. However, with the introduction of SHA-256 support, this assumption no longer holds true. Replace the hardcoded $z40 with a call to `git rev-parse --null-oid` so the sample hook becomes hash-agnostic.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 templates/hooks--pre-push.sample | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample
index 64b5707553..b3bc5276bf 100755
--- a/templates/hooks--pre-push.sample
+++ b/templates/hooks--pre-push.sample
@@ -22,16 +22,16 @@
 remote="$1"
 url="$2"
 
-z40=0000000000000000000000000000000000000000
+null_oid="$(git rev-parse --null-oid)"
 
 while read local_ref local_sha remote_ref remote_sha
 do
-	if [ "$local_sha" = $z40 ]
+	if [ "$local_sha" = "$null_oid" ]
 	then
 		# Handle delete
 		:
 	else
-		if [ "$remote_sha" = $z40 ]
+		if [ "$remote_sha" = "$null_oid" ]
 		then
 			# New branch, examine all commits
 			range="$local_sha"
-- 
2.28.0.618.gf4bc123cb7
Previous: Eric SunshineNext: Eric Sunshine
Message 14 of 23 in “sample hooks: become hash agnostic”
  1. 0/4 sample hooks: become hash agnosticDenton Liu, Sep 18, 2020
  2. 2/4 builtin/rev-parse: learn --null-oidDenton Liu, Sep 18, 2020
  3. Taylor BlauSep 18, 2020
  4. Taylor BlauSep 18, 2020
  5. Junio C HamanoSep 18, 2020
  6. Taylor BlauSep 18, 2020
  7. brian m. carlsonSep 18, 2020
  8. Chris TorekSep 20, 2020
  9. brian m. carlsonSep 20, 2020
  10. Taylor BlauSep 20, 2020
  11. Andreas SchwabSep 20, 2020
  12. 1/4 hooks--pre-push.sample: prefer $() for command substitutionDenton Liu, Sep 18, 2020
  13. Eric SunshineSep 18, 2020
  14. 3/4 hooks--pre-push.sample: use hash-agnostic null OIDDenton Liu, Sep 18, 2020
  15. Eric SunshineSep 18, 2020
  16. 4/4 hooks--update.sample: use hash-agnostic null OIDDenton Liu, Sep 18, 2020
  17. Eric SunshineSep 18, 2020
  18. brian m. carlsonSep 18, 2020
  19. 0/3 sample hooks: become hash agnosticDenton Liu, Sep 23, 2020
  20. 1/3 hooks--pre-push.sample: modernize scriptDenton Liu, Sep 23, 2020
  21. 3/3 hooks--update.sample: use hash-agnostic zero OIDDenton Liu, Sep 23, 2020
  22. 2/3 hooks--pre-push.sample: use hash-agnostic zero OIDDenton Liu, Sep 23, 2020
  23. Junio C HamanoSep 23, 2020

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.