@matheusbsbs / matheus-bagliano / commits / 024e5b31af
Fork 0

post-receive-email example hook: detect rewind-only updates and output sensible message

Sometimes a non-fast-forward update doesn't add new commits, it merely removes old commits. This patch adds support for detecting that and outputting a more correct message. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Andy Parkins committed Apr 26, 2007 at 22:36 UTC 024e5b31af6f06d39542ab1a44de358d7734388b
1 file changed +54 -23
contrib/hooks/post-receive-email
+54 -23
@@ -327,36 +327,67 @@ generate_update_branch_email()
327 if [ -z "$fastforward" ]; then
328 echo " from $oldrev ($oldrev_type)"
329 else
330 + # 1. Existing revisions were removed. In this case newrev is a
331 + # subset of oldrev - this is the reverse of a fast-forward,
332 + # a rewind
333 + # 2. New revisions were added on top of an old revision, this is
334 + # a rewind and addition.
335 +
336 + # (1) certainly happened, (2) possibly. When (2) hasn't happened,
337 + # we set a flag to indicate that no log printout is required.
338 +
339 echo ""
331 - echo "This update added new revisions after undoing old revisions. That is to"
332 - echo "say, the old revision is not a strict subset of the new revision. This"
333 - echo "situation occurs when you --force push a change and generate a"
334 - echo "repository containing something like this:"
335 - echo ""
336 - echo " * -- * -- B -- O -- O -- O ($oldrev)"
337 - echo " \\"
338 - echo " N -- N -- N ($newrev)"
339 - echo ""
340 - echo "When this happens we assume that you've already had alert emails for all"
341 - echo "of the O revisions, and so we here report only the revisions in the N"
342 - echo "branch from the common base, B."
340 +
341 + # Find the common ancestor of the old and new revisions and compare
342 + # it with newrev
343 + baserev=$(git merge-base $oldrev $newrev)
344 + rewind_only=""
345 + if [ "$baserev" = "$newrev" ]; then
346 + echo "This update discarded existing revisions and left the branch pointing at"
347 + echo "a previous point in the repository history."
348 + echo ""
349 + echo " * -- * -- N ($newrev)"
350 + echo " \\"
351 + echo " O -- O -- O ($oldrev)"
352 + echo ""
353 + echo "The removed revisions are not necessarilly gone - if another reference"
354 + echo "still refers to them they will stay in the repository."
355 + rewind_only=1
356 + else
357 + echo "This update added new revisions after undoing existing revisions. That is"
358 + echo "to say, the old revision is not a strict subset of the new revision. This"
359 + echo "situation occurs when you --force push a change and generate a repository"
360 + echo "containing something like this:"
361 + echo ""
362 + echo " * -- * -- B -- O -- O -- O ($oldrev)"
363 + echo " \\"
364 + echo " N -- N -- N ($newrev)"
365 + echo ""
366 + echo "When this happens we assume that you've already had alert emails for all"
367 + echo "of the O revisions, and so we here report only the revisions in the N"
368 + echo "branch from the common base, B."
369 + fi
370 fi
371
372 echo ""
346 - echo "Those revisions listed above that are new to this repository have"
347 - echo "not appeared on any other notification email; so we list those"
348 - echo "revisions in full, below."
373 + if [ -z "$rewind_only" ]; then
374 + echo "Those revisions listed above that are new to this repository have"
375 + echo "not appeared on any other notification email; so we list those"
376 + echo "revisions in full, below."
377
350 - echo ""
351 - echo $LOGBEGIN
352 - git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
353 - git rev-list --pretty --stdin $oldrev..$newrev
378 + echo ""
379 + echo $LOGBEGIN
380 + git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
381 + git rev-list --pretty --stdin $oldrev..$newrev
382
355 - # XXX: Need a way of detecting whether git rev-list actually outputted
356 - # anything, so that we can issue a "no new revisions added by this
357 - # update" message
383 + # XXX: Need a way of detecting whether git rev-list actually outputted
384 + # anything, so that we can issue a "no new revisions added by this
385 + # update" message
386
359 - echo $LOGEND
387 + echo $LOGEND
388 + else
389 + echo "No new revisions were added by this update."
390 + fi
391
392 # The diffstat is shown from the old revision to the new revision. This
393 # is to show the truth of what happened in this change. There's no point