1#!/bin/sh 2# Check file names in git commits for GNU Emacs. 3 4# Copyright 2014-2021 Free Software Foundation, Inc. 5 6# This file is part of GNU Emacs. 7 8# GNU Emacs is free software: you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation, either version 3 of the License, or 11# (at your option) any later version. 12 13# GNU Emacs is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17 18# You should have received a copy of the GNU General Public License 19# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. 20 21LC_ALL=C 22export LC_ALL 23 24exec >&2 25 26. git-sh-setup 27 28# When doing a two-way merge, ignore problems that came from the other 29# side of the merge. 30head=HEAD 31if test -r "$GIT_DIR"/MERGE_HEAD && test "$GIT_MERGE_CHECK_OTHER" != true; then 32 merge_heads=`cat "$GIT_DIR"/MERGE_HEAD` || exit 33 for merge_head in $merge_heads; do 34 case $head in 35 HEAD) head=$merge_head;; 36 # For multi-head merges, there's no easy way to ignore merged-in 37 # changes. But if you're doing multi-head merges, presumably 38 # you know how to handle any ensuing problems. 39 *) head=HEAD; break;; 40 esac 41 done 42fi 43 44git_diff='git diff --cached --name-only --diff-filter=A' 45 46# 'git diff' will backslash escape tabs and newlines, so we don't have 47# to worry about word splitting here. 48$git_diff $head | sane_egrep 'ChangeLog|^-|/-|[^-+./_0-9A-Z_a-z]' | while IFS= read -r new_name; do 49 case $new_name in 50 -* | */-*) 51 echo "$new_name: File name component begins with '-'." 52 exit 1;; 53 ChangeLog | */ChangeLog) 54 echo "$new_name: Please use git commit messages, not ChangeLog files." 55 exit 1;; 56 *) 57 echo "$new_name: File name does not consist of -+./_ or ASCII letters or digits." 58 exit 1;; 59 esac 60done 61 62# The '--check' option of git diff-index makes Git complain if changes 63# introduce whitespace errors. This can be a pain when editing test 64# files that deliberately contain lines with trailing whitespace. 65# To work around the problem you can run a command like 'git config 66# core.whitespace -trailing-space'. It may be better to revamp the 67# tests so that trailing spaces are generated on the fly rather than 68# being committed as source. 69 70exec git diff-index --check --cached $head -- 71