#!/bin/bash # Copyright 2015-2016 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Author: Ulrich Müller refname=$1 oldrev=$2 newrev=$3 # 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 ) # git diff --name-only outputs \t, \n, \", and \\ for TAB, LF, ", and \, # respectively. This is OK because the result won't be matched by the regex. badfiles=$(git diff --name-only --diff-filter=ACR "${oldrev}" "${newrev}" \ | grep -Ev -e "${regex}") ret=0 IFS=$'\n' for path in ${badfiles}; do for e in "${exceptions[@]}"; do [[ ${path} = "${e}" ]] && continue 2 done echo "Path \"${path}\" violates file naming rules" >&2 ret=1 done exit ${ret}