forked from antrea-io/antrea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-push
53 lines (48 loc) · 1.69 KB
/
pre-push
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# Copyright 2022 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script will verify sign-off info and prevent push of commits if sign-off is missing.
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <LOCAL_REF> <LOCAL_SHA> <REMOTE_REF> <REMOTE_SHA>
#
# https://www.git-scm.com/docs/githooks#_pre_push
DUMMY_SHA=0000000000000000000000000000000000000000
AUTHOR=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/\1/p')
while read -r LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA;
do
if [ "$LOCAL_SHA" = $DUMMY_SHA ]
then
# Branch deleted. Do nothing.
exit 0
else
if [ "$REMOTE_SHA" = $DUMMY_SHA ]
then
RANGE="$LOCAL_SHA~1..$LOCAL_SHA"
else
RANGE="$REMOTE_SHA..$LOCAL_SHA"
fi
NOT_SIGNED_OFF=$(git rev-list --no-merges --author "$AUTHOR" --grep="^Signed-off-by: " --invert-grep "$RANGE")
if [ -n "$NOT_SIGNED_OFF" ]
then
echo >&2 "ERROR: The following commits have no DCO sign-off:"
while read -r commit; do
echo " $(git log --pretty=oneline --abbrev-commit -n 1 "$commit")"
done <<< "$NOT_SIGNED_OFF"
exit 1
fi
fi
done
exit 0