all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>,  29197@debbugs.gnu.org
Subject: bug#29197: 27.0.50; pre-commit checks for new files against "head"
Date: Wed, 14 Feb 2018 20:03:50 -0500	[thread overview]
Message-ID: <87lgfv83nt.fsf@gmail.com> (raw)
In-Reply-To: <CAM-tV-_uJW6+0u6=QkFx5iDhTbSzHNABAdw2VbsMT6SLmK6okQ@mail.gmail.com> (Noam Postavsky's message of "Tue, 7 Nov 2017 16:36:37 -0500")

[-- Attachment #1: Type: text/plain, Size: 819 bytes --]

Noam Postavsky <npostavs@users.sourceforge.net> writes:

>> I think the warning should be improved:
>> - I shouldn't get a warning in the above case, since this commit doesn't
>>   *add* those files (they weren't on origin/master admittedly but they were
>>   already on HEAD).
>
> We could choose which side of the merge to check based on an
> environment var (that was considered in the thread I referenced above,
> but we didn't see much of a use case at the time). Or is it possible
> to check only changes from the merge itself (i.e., in case of conflict
> resolution)?
>
>> - the warning should give me some hint about which file fails the test.
>
> Yeah, that would make sense.

This seems fairly difficult to do while keeping in standard bourne shell
syntax.  Not sure how to catch file names with whitespace.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2187 bytes --]

From fa94e7452be5ffb4d63ad2a40fc5b9fdeed3fed0 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Wed, 14 Feb 2018 19:58:07 -0500
Subject: [PATCH v1] ; 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 | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/build-aux/git-hooks/pre-commit b/build-aux/git-hooks/pre-commit
index 5e42dab233..33d8c91168 100755
--- a/build-aux/git-hooks/pre-commit
+++ b/build-aux/git-hooks/pre-commit
@@ -28,7 +28,7 @@ LC_ALL=
 # 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,13 +42,6 @@ head=
 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
   case $new_name in
@@ -58,9 +51,20 @@ nbadchars=
     ChangeLog | */ChangeLog)
       echo "$new_name: Please use git commit messages, not ChangeLog files."
       exit 1;;
+    *[^-+./_0-9A-Z_a-z]*)
+      echo "$new_name: File name does not consist of -+./_ or ASCII letters or digits."
+      exit 1;;
   esac
 done
 
+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 "A file name has whitespace."
+  exit 1
+fi
+
 # The '--check' option of git diff-index makes Git complain if changes
 # introduce whitespace errors.  This can be a pain when editing test
 # files that deliberately contain lines with trailing whitespace.
-- 
2.11.0


  reply	other threads:[~2018-02-15  1:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07 19:18 bug#29197: 27.0.50; pre-commit checks for new files against "head" Stefan Monnier
2017-11-07 21:36 ` Noam Postavsky
2018-02-15  1:03   ` Noam Postavsky [this message]
2018-08-28 12:21     ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lgfv83nt.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=29197@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.