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

Sample pre-push hook can crash

From
Stephen Morton <stephen.c.morton@gmail.com>
Date
Mar 10, 2016, 21:22 UTC
Message-ID
<CAH8BJxHeyfpKsvjGfg5ZJ5YDQk6pzZp4ufHVEV=cFriL8j_4uw@mail.gmail.com>

The sample pre-push hook provided with git [1] will crash if the local repo is not up to date with the remote as $remote_sha is not present in the local repo. I'm not sure if this patch is exactly correct, it's just provided as an example.

Given that people are likely crafting their own solutions based on the examples, it's probably good to get right.

diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample
index 6187dbf..99ed984 100755
--- a/templates/hooks--pre-push.sample
+++ b/templates/hooks--pre-push.sample
@@ -36,9 +36,9 @@ do
                        # New branch, examine all commits
                        range="$local_sha"
                else
                        # Update to existing branch, examine new commits
-                       range="$remote_sha..$local_sha"
+                       range="@{u}..$local_sha"
                fi

                # Check for WIP commit
                commit=`git rev-list -n 1 --grep '^WIP' "$range"`


(This is just something I noticed and thought you might be interested
in, but is not important to me. I actually do care about the smudge
filter issue.)

Stephen

[1] https://github.com/git/git/blob/master/templates/hooks--pre-push.sample
Next: Junio C Hamano
Message 1 of 5 in “Sample pre-push hook can crash”
  1. Stephen MortonMar 10, 2016
  2. Junio C HamanoMar 10, 2016
  3. Stephen MortonMar 11, 2016
  4. Junio C HamanoMar 11, 2016
  5. Stephen MortonMar 11, 2016

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.