aboutsummaryrefslogtreecommitdiff
blob: 0365dec764a8678fcfcf48f1efbb66d261c34e0c (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
#!/bin/bash
# gentoo-infra: infra/githooks.git:local/update-04-utf8
# Copyright 2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2 or later

# Author: Michał Górny <mgorny@gentoo.org>

refname=$1
oldrev=$2
newrev=$3

export LC_MESSAGES=C

# 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

ret=0
while read commithash; do
    # verify that the commit object (including author, committer, commit
    # message) is valid UTF-8
    if ! git cat-file -p "${commithash}" | iconv -f utf8 -t utf8 &>/dev/null
    then
        echo "Commit ${commithash} contains invalid UTF-8 in the commit metadata"
        ret=1
    fi
done < <(git rev-list "${oldrev}..${newrev}")

exit ${ret}