From 61c1fffe7b1ff671849525c5c336d8bfe9c062b2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 29 May 2023 10:50:55 -0700 Subject: [PATCH] scripts: sync git-hooks from coreutils --- scripts/git-hooks/applypatch-msg | 4 ++-- scripts/git-hooks/commit-msg | 20 ++++++++++++-------- scripts/git-hooks/pre-applypatch | 4 ++-- scripts/git-hooks/pre-commit | 29 +++++++++++++++-------------- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/scripts/git-hooks/applypatch-msg b/scripts/git-hooks/applypatch-msg index a5d7b84..8b2a2fe 100755 --- a/scripts/git-hooks/applypatch-msg +++ b/scripts/git-hooks/applypatch-msg @@ -10,6 +10,6 @@ # To enable this hook, rename this file to "applypatch-msg". . git-sh-setup -commitmsg="$(git rev-parse --git-path hooks/commit-msg)" -test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +test -x "$GIT_DIR/hooks/commit-msg" && + exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} : diff --git a/scripts/git-hooks/commit-msg b/scripts/git-hooks/commit-msg index 888b83b..6affb71 100755 --- a/scripts/git-hooks/commit-msg +++ b/scripts/git-hooks/commit-msg @@ -16,7 +16,7 @@ $editor = "vi" if $? != 0 or $editor =~ /^\s*\z/; my @valid = qw( diff diff3 cmp sdiff - gnulib tests maint doc build scripts + all gnulib tests maint doc build scripts ); my $v_or = join '|', @valid; my $valid_regex = qr/^(?:$v_or)$/; @@ -79,7 +79,7 @@ sub check_msg($$) my ($log_file, $line_ref) = @_; local *LOG; - open LOG, '<', $log_file + open LOG, '<:utf8', $log_file or return "failed to open for reading: $!"; @$line_ref = ; close LOG; @@ -109,21 +109,24 @@ sub check_msg($$) and return 'second line must be empty'; # Limit line length to allow for the ChangeLog's leading TAB. + my $max_len = 72; foreach my $line (@line) { - 72 < length $line && $line =~ /^[^#]/ - and return 'line longer than 72'; + last if $line =~ '.*-{24} >8 -{24}$'; + my $len = length $line; + $max_len < $len && $line =~ /^[^#]/ + and return "line length ($len) greater than than max: $max_len"; } my $buf = join ("\n", @line) . "\n"; $buf =~ m!https?://bugzilla\.redhat\.com/show_bug\.cgi\?id=(\d+)!s - and return "use shorter http://bugzilla.redhat.com/$1"; + and return "use shorter https://bugzilla.redhat.com/$1"; $buf =~ m!https?://debbugs\.gnu\.org/(?:cgi/bugreport\.cgi\?bug=)?(\d+)!s - and return "use shorter http://bugs.gnu.org/$1"; + and return "use shorter https://bugs.gnu.org/$1"; - $buf =~ /^ *Signed-off-by:/mi - and return q(do not use "Signed-off-by:"); + $buf =~ m!https://lists\.gnu\.org/archive/html/!s + and return "use '/r/' in place of '/archive/html/' in lists.gnu.org URLs"; return ''; } @@ -141,6 +144,7 @@ sub check_msg($$) $err eq '' and last; $err = "$ME: $err\n"; + -t STDOUT or die $err; warn $err; # Insert the diagnostic as a comment on the first line of $log_file. rewrite $log_file, $err, \@line; diff --git a/scripts/git-hooks/pre-applypatch b/scripts/git-hooks/pre-applypatch index 4142082..b1f187c 100755 --- a/scripts/git-hooks/pre-applypatch +++ b/scripts/git-hooks/pre-applypatch @@ -9,6 +9,6 @@ # To enable this hook, rename this file to "pre-applypatch". . git-sh-setup -precommit="$(git rev-parse --git-path hooks/pre-commit)" -test -x "$precommit" && exec "$precommit" ${1+"$@"} +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} : diff --git a/scripts/git-hooks/pre-commit b/scripts/git-hooks/pre-commit index 68d62d5..18c4829 100755 --- a/scripts/git-hooks/pre-commit +++ b/scripts/git-hooks/pre-commit @@ -15,13 +15,13 @@ else against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi -# If you want to allow non-ASCII filenames set this variable to true. -allownonascii=$(git config --bool hooks.allownonascii) +# If you want to allow non-ascii filenames set this variable to true. +allownonascii=$(git config hooks.allownonascii) # Redirect output to stderr. exec 1>&2 -# Cross platform projects tend to avoid non-ASCII filenames; prevent +# Cross platform projects tend to avoid non-ascii filenames; prevent # them from being added to the repository. We exploit the fact that the # printable range starts at the space character and ends with tilde. if [ "$allownonascii" != "true" ] && @@ -31,17 +31,18 @@ if [ "$allownonascii" != "true" ] && test $(git diff --cached --name-only --diff-filter=A -z $against | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 then - cat <<\EOF -Error: Attempt to add a non-ASCII file name. - -This can cause problems if you want to work with people on other platforms. - -To be portable it is advisable to rename the file. - -If you know what you are doing you can disable this check using: - - git config hooks.allownonascii true -EOF + echo "Error: Attempt to add a non-ascii file name." + echo + echo "This can cause problems if you want to work" + echo "with people on other platforms." + echo + echo "To be portable it is advisable to rename the file ..." + echo + echo "If you know what you are doing you can disable this" + echo "check using:" + echo + echo " git config hooks.allownonascii true" + echo exit 1 fi