blob: 6871175cd0eac97a2f8d7578a4815d5a8615f039 (
plain)
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
|
#!/bin/bash
# gentoo-infra: infra/githooks.git:local/update-03-filename
# Copyright 2015-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2 or later
# Author: Ulrich Müller <ulm@gentoo.org>
refname=$1
oldrev=$2
newrev=$3
# skip non-master commits
[[ ${refname} == refs/heads/master ]] || exit 0
# special cases
zeros=0000000000000000000000000000000000000000
# branch removal
[[ ${newrev} == "${zeros}" ]] && exit 0
# new branch; try to find a merge base with master
if [[ ${oldrev} == "${zeros}" && ${refname} != refs/heads/master ]]; then
mergebase=$(git merge-base refs/heads/master "${newrev}")
[[ -n ${mergebase} ]] && oldrev=${mergebase}
[[ -z ${mergebase} ]] && echo "WARNING: No common commits with master!"
fi
# Filenames must contain only the characters [A-Za-z0-9._+-] and must
# not begin with a dot, a hyphen, or a plus sign.
# https://devmanual.gentoo.org/general-concepts/tree/#what-belongs-in-the-tree%3F
# https://devmanual.gentoo.org/ebuild-writing/file-format/#file-naming-rules
export LC_ALL=C
regex='^([A-Za-z0-9_][A-Za-z0-9._+-]*/)*[A-Za-z0-9_][A-Za-z0-9._+-]*$'
exceptions=(
.gitignore
metadata/.gitignore
)
ret=0
while IFS= read -r -d $'\0' path; do
for e in "${exceptions[@]}"; do
[[ ${path} = "${e}" ]] && continue 2
done
echo "Path \"${path}\" violates file naming rules" >&2
ret=1
done < <(git diff -z --name-only --diff-filter=ACR "${oldrev}" "${newrev}" \
| grep -z -Ev -e "${regex}")
# Preceding line needs >=grep-2.24 for -z working correctly (bug #574662)
exit ${ret}
|