forked from GoogleCloudPlatform/PerfKitBenchmarker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-push
More file actions
executable file
·58 lines (48 loc) · 1.9 KB
/
pre-push
File metadata and controls
executable file
·58 lines (48 loc) · 1.9 KB
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
54
55
56
57
58
#!/bin/bash
# Copyright 2015 PerfKitBenchmarker Authors. All rights reserved.
#
# 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.
# Pre-push hooks are tricky since there's no easy way to distinguish
# which parts of the history are new and which are inherited from
# parents without knowing the branch base point. For now, make this
# check opt-in.
set -euo pipefail
HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
REMOTE="$1"
URL="$2"
Z40=0000000000000000000000000000000000000000
if [[ -z "${PKB_BASE:-}" ]]; then
echo >&2 "Skipping pre-push check. Set PKB_BASE to a base branch such as 'upstream/dev' to enable."
exit 0
fi
if ! git rev-parse --verify --quiet "$PKB_BASE" >/dev/null; then
echo >&2 "Skipping pre-push check: cannot find PKB_BASE='$PKB_BASE'."
exit 0
fi
# Loop over the provided refs being pushed and collect the
# union set of changed files.
modified_files=($(
IFS=' '
while read local_ref local_sha remote_ref remote_sha; do
# Nothing to do for delete.
[ "$local_sha" = "$Z40" ] && continue
# Find a common ancestor with the origin branch.
base=$(git merge-base "$PKB_BASE" "$local_sha")
# Get list of files added/changed/moved relative to the
# common ancestor.
git diff --name-only --diff-filter ACM "$base..$local_sha"
done | sort -u
))
if [[ "${#modified_files[@]}" -ne 0 ]]; then
"${HOOKS_DIR}/check" "${modified_files[@]}" >&2
fi