From: Junio C Hamano <gitster@pobox•com>
To: Stephen Morton <stephen.c.morton@gmail•com>
Cc: "git\@vger.kernel.org" <git@vger•kernel.org>
Subject: Re: Sample pre-push hook can crash
Date: Thu, 10 Mar 2016 13:43:08 -0800 [thread overview]
Message-ID: <xmqq37rydn6b.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <CAH8BJxHeyfpKsvjGfg5ZJ5YDQk6pzZp4ufHVEV=cFriL8j_4uw@mail.gmail.com> (Stephen Morton's message of "Thu, 10 Mar 2016 16:22:14 -0500")
Stephen Morton <stephen.c.morton@gmail•com> writes:
> 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.
It's probably good to get right, but I do not think use of @{u} is
making it right, unfortunately. You may not necessarily have @{u}
configured, and you may not even pushing to the configured remote
branch.
The spirit of the sample hook, I think, is to validate the new
commits you are publishing, so if you cannot even determine which
ones are new and which ones are not, failing the "push" by exiting
with non-zero status is the right behaviour for this sample.
So perhaps something like this may be more appropriate as an
example.
templates/hooks--pre-push.sample | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample
index 6187dbf..7ef6780 100755
--- a/templates/hooks--pre-push.sample
+++ b/templates/hooks--pre-push.sample
@@ -41,7 +41,12 @@ do
fi
# Check for WIP commit
- commit=`git rev-list -n 1 --grep '^WIP' "$range"`
+ commit=`git rev-list -n 1 --grep '^WIP' "$range"` || {
+ # we do not even know about the range...
+ echo >&2 "Non-ff update to $remote_ref"
+ echo >&2 "fetch from there first"
+ exit 1
+ }
if [ -n "$commit" ]
then
echo >&2 "Found WIP commit in $local_ref, not pushing"
next prev parent reply other threads:[~2016-03-10 21:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-10 21:22 Sample pre-push hook can crash Stephen Morton
2016-03-10 21:43 ` Junio C Hamano [this message]
2016-03-11 14:33 ` Stephen Morton
2016-03-11 20:04 ` Junio C Hamano
2016-03-11 20:35 ` Stephen Morton
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=xmqq37rydn6b.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=stephen.c.morton@gmail$(echo .)com \
/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