Ticket #20953: pre-push

File pre-push, 1.8 KB (added by Anssi Kääriäinen, 11 years ago)

pre-push script to prevent force-pusing

Line 
1#!/bin/sh
2
3# An example hook script to verify what is about to be pushed. Called by "git
4# push" after it has checked the remote status, but before anything has been
5# pushed. If this script exits with a non-zero status nothing will be pushed.
6#
7# This hook is called with the following parameters:
8#
9# $1 -- Name of the remote to which the push is being done
10# $2 -- URL to which the push is being done
11#
12# If pushing without using a named remote those arguments will be equal.
13#
14# Information about the commits which are being pushed is supplied as lines to
15# the standard input in the form:
16#
17# <local ref> <local sha1> <remote ref> <remote sha1>
18#
19# This sample shows how to prevent push of commits where the log message starts
20# with "WIP" (work in progress).
21
22remote="$1"
23django_origin="origin"
24if [ "$remote" != "$django_origin" ]
25then
26 # Not dealing with django-origin, so don't do anythin
27 return 0
28fi
29url="$2"
30
31z40=0000000000000000000000000000000000000000
32
33IFS=' '
34while read local_ref local_sha remote_ref remote_sha
35do
36 if [ "$local_sha" = $z40 ]
37 then
38 echo "Seems like a delete of a django-origin branch. Use --no-verify if you really want to do that."
39 exit 1
40 else
41 if [ "$remote_sha" = $z40 ]
42 then
43 # New branch, examine all commits
44 echo "Seems like you are trying to push a new branch to upstream. Use --no-verify if you really want to do that."
45 exit 1
46 fi
47
48 # Check the range, if it is empty this is likely a force-push (no idea why)
49 commit=`git rev-list "$local_sha" |grep "$remote_sha"`
50 if [ -z "$commit" ]
51 then
52 echo "This seems like force-push to upstream. Use --no-verify if you really want to do that. HINT: you don't!"
53 exit 1
54 fi
55 fi
56done
57
58exit 0
Back to Top