emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 fca935e 1/3: ; Let pre-commit git hook check merg


From: Noam Postavsky
Subject: [Emacs-diffs] emacs-26 fca935e 1/3: ; Let pre-commit git hook check merged in changes (Bug#29197)
Date: Tue, 28 Aug 2018 08:14:47 -0400 (EDT)

branch: emacs-26
commit fca935e4abe817130abb2676ec2f37b73e4f45f4
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    ; Let pre-commit git hook check merged in changes (Bug#29197)
    
    * build-aux/git-hooks/pre-commit: If GIT_MERGE_CHECK_OTHER is 'true',
    check changes against the merge target, rather than the current
    branch.  Include file name when giving error message about
    non-standard characters.
---
 build-aux/git-hooks/pre-commit | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/build-aux/git-hooks/pre-commit b/build-aux/git-hooks/pre-commit
index 5e42dab..c0455fb 100755
--- a/build-aux/git-hooks/pre-commit
+++ b/build-aux/git-hooks/pre-commit
@@ -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,10 @@ 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 | sane_egrep '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 +53,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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]