diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
commit | 650c20f1ca4e07591a727e1cfcc74b3363d15985 (patch) | |
tree | 85d11f6437cde22f410c25e0e5f71a3131ebd07d /build-aux/git-hooks | |
parent | 8869332684c2302b5ba1ead4568bbc7ba1c0183e (diff) | |
parent | 4b85ae6a24380fb67a3315eaec9233f17a872473 (diff) | |
download | emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.gz emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.bz2 emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.zip |
Merge 'master' into noverlay
Diffstat (limited to 'build-aux/git-hooks')
-rwxr-xr-x | build-aux/git-hooks/commit-msg | 27 | ||||
-rwxr-xr-x | build-aux/git-hooks/pre-commit | 20 | ||||
-rwxr-xr-x | build-aux/git-hooks/prepare-commit-msg | 45 |
3 files changed, 80 insertions, 12 deletions
diff --git a/build-aux/git-hooks/commit-msg b/build-aux/git-hooks/commit-msg index 39450865cb8..bb4f358c5e4 100755 --- a/build-aux/git-hooks/commit-msg +++ b/build-aux/git-hooks/commit-msg @@ -1,7 +1,7 @@ #!/bin/sh # Check the format of GNU Emacs change log entries. -# Copyright 2014-2017 Free Software Foundation, Inc. +# Copyright 2014-2022 Free Software Foundation, Inc. # This file is part of GNU Emacs. @@ -44,7 +44,7 @@ if test "$at_sign" != @; then fi # Check the log entry. -exec $awk -v at_sign="$at_sign" -v cent_sign="$cent_sign" ' +exec $awk -v at_sign="$at_sign" -v cent_sign="$cent_sign" -v file="$1" ' BEGIN { # These regular expressions assume traditional Unix unibyte behavior. # They are needed for old or broken versions of awk, e.g., @@ -66,8 +66,12 @@ exec $awk -v at_sign="$at_sign" -v cent_sign="$cent_sign" ' non_print = "[^[:print:]]" } } + c_lower = "abcdefghijklmnopqrstuvwxyz" + unsafe_gnu_url = "(http|ftp)://([" c_lower ".]*\\.)?(gnu|fsf)\\.org" } + { input[NR] = $0 } + /^#/ { # Ignore every line after a scissors line. if (/^# *---* *(>[8%]|[8%]<) *---* *$/) { exit } @@ -125,6 +129,10 @@ exec $awk -v at_sign="$at_sign" -v cent_sign="$cent_sign" ' status = 1 } + $0 ~ unsafe_gnu_url { + needs_rewriting = 1 + } + $0 ~ non_print { print "Unprintable character in commit message" status = 1 @@ -135,6 +143,21 @@ exec $awk -v at_sign="$at_sign" -v cent_sign="$cent_sign" ' print "Empty commit message" status = 1 } + if (status == 0 && needs_rewriting) { + for (i = 1; i <= NR; i++) { + line = input[i] + while (match(line, unsafe_gnu_url)) { + prefix = substr(line, 1, RSTART - 1) + suffix = substr(line, RSTART) + line = prefix "https:" substr(suffix, 5 + (suffix ~ /^http:/)) + } + print line >file + } + if (close(file) != 0) { + print "Cannot rewrite: " file + status = 1 + } + } if (status != 0) { print "Commit aborted; please see the file 'CONTRIBUTE'" } diff --git a/build-aux/git-hooks/pre-commit b/build-aux/git-hooks/pre-commit index 68a0c33d4a1..49bf05f2d9f 100755 --- a/build-aux/git-hooks/pre-commit +++ b/build-aux/git-hooks/pre-commit @@ -1,7 +1,7 @@ #!/bin/sh # Check file names in git commits for GNU Emacs. -# Copyright 2014-2017 Free Software Foundation, Inc. +# Copyright 2014-2022 Free Software Foundation, Inc. # This file is part of GNU Emacs. @@ -28,7 +28,7 @@ exec >&2 # When doing a two-way merge, ignore problems that came from the other # side of the merge. head=HEAD -if test -r "$GIT_DIR"/MERGE_HEAD; then +if test -r "$GIT_DIR"/MERGE_HEAD && test "$GIT_MERGE_CHECK_OTHER" != true; then merge_heads=`cat "$GIT_DIR"/MERGE_HEAD` || exit for merge_head in $merge_heads; do case $head in @@ -42,15 +42,12 @@ if test -r "$GIT_DIR"/MERGE_HEAD; then fi git_diff='git diff --cached --name-only --diff-filter=A' -ok_chars='\0+[=-=]./0-9A-Z_a-z' -nbadchars=`$git_diff -z $head | tr -d "$ok_chars" | wc -c` -if test "$nbadchars" -ne 0; then - echo "File name does not consist of -+./_ or ASCII letters or digits." - exit 1 -fi - -for new_name in `$git_diff $head`; do +# 'git diff' will backslash escape tabs and newlines, so we don't have +# to worry about word splitting here. +$git_diff $head | +LC_ALL=C grep -E 'ChangeLog|^-|/-|[^-+./_0-9A-Z_a-z]' | +while IFS= read -r new_name; do case $new_name in -* | */-*) echo "$new_name: File name component begins with '-'." @@ -58,6 +55,9 @@ for new_name in `$git_diff $head`; do ChangeLog | */ChangeLog) echo "$new_name: Please use git commit messages, not ChangeLog files." exit 1;; + *) + echo "$new_name: File name does not consist of -+./_ or ASCII letters or digits." + exit 1;; esac done diff --git a/build-aux/git-hooks/prepare-commit-msg b/build-aux/git-hooks/prepare-commit-msg new file mode 100755 index 00000000000..7dc36f22193 --- /dev/null +++ b/build-aux/git-hooks/prepare-commit-msg @@ -0,0 +1,45 @@ +#!/bin/sh +# Check the format of GNU Emacs change log entries. + +# Copyright 2019-2022 Free Software Foundation, Inc. + +# This file is part of GNU Emacs. + +# GNU Emacs is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# GNU Emacs is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +# Prefer gawk if available, as it handles NUL bytes properly. +if type gawk >/dev/null 2>&1; then + awk="gawk" +else + awk="awk" +fi + +exec $awk ' + # Catch the case when someone ran git-commit with -s option, + # which automatically adds Signed-off-by. + /^Signed-off-by: / { + print "'\''Signed-off-by:'\'' in commit message" + status = 1 + } + END { + if (status != 0) { + print "Commit aborted; please see the file 'CONTRIBUTE'" + } + exit status + } +' <"$COMMIT_MSG_FILE" |