Fix Android 6/7 problems in Tramp
[emacs.git] / build-aux / git-hooks / pre-commit
blob548bf933f0c8557d9565efece6fd31c45787283c
1 #!/bin/sh
2 # Check file names in git commits for GNU Emacs.
4 # Copyright 2014-2017 Free Software Foundation, Inc.
6 # This file is part of GNU Emacs.
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.
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.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 LC_ALL=C
22 export LC_ALL
24 exec >&2
26 . git-sh-setup
28 # When doing a two-way merge, ignore problems that came from the other
29 # side of the merge.
30 head=HEAD
31 if test -e "$GIT_DIR"/MERGE_HEAD; 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
44 git_diff='git diff --cached --name-only --diff-filter=A'
45 ok_chars='\0+[=-=]./0-9A-Z_a-z'
46 nbadchars=`$git_diff -z $head | tr -d "$ok_chars" | wc -c`
48 if test "$nbadchars" -ne 0; then
49 echo "File name does not consist of -+./_ or ASCII letters or digits."
50 exit 1
53 for new_name in `$git_diff $head`; do
54 case $new_name in
55 -* | */-*)
56 echo "$new_name: File name component begins with '-'."
57 exit 1;;
58 ChangeLog | */ChangeLog)
59 echo "$new_name: Please use git commit messages, not ChangeLog files."
60 exit 1;;
61 esac
62 done
64 # The '--check' option of git diff-index makes Git complain if changes
65 # introduce whitespace errors. This can be a pain when editing test
66 # files that deliberately contain lines with trailing whitespace.
67 # To work around the problem you can run a command like 'git config
68 # core.whitespace -trailing-space'. It may be better to revamp the
69 # tests so that trailing spaces are generated on the fly rather than
70 # being committed as source.
72 exec git diff-index --check --cached $head --