From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: martin rudalics <rudalics@gmx.at>,
emacs-devel <emacs-devel@gnu.org>,
Andreas Schwab <schwab@suse.de>,
Yuri Khan <yuri.v.khan@gmail.com>
Subject: Re: git pre-commit hook for merges (WAS: master has switched from Automake to GNU Make)
Date: Sat, 29 Apr 2017 14:00:26 -0400 [thread overview]
Message-ID: <CAM-tV-8-QnWDJ04cQXt1jPr-ufrZ6X4p7yTNmrsS7aJ5HrSKWw@mail.gmail.com> (raw)
In-Reply-To: <955c464e-5833-10fd-9c02-d7edda70e488@cs.ucla.edu>
[-- Attachment #1: Type: text/plain, Size: 687 bytes --]
On Wed, Apr 12, 2017 at 2:26 PM, Paul Eggert <eggert@cs.ucla.edu> wrote:
>>
>> Perhaps we should change the hook so that it doesn't complain about
>> problems from merges?
>
> Something like that might make sense, yes, for people in Alan's situation.
> When I do a merge, though, I'd rather see problems from the other side (so
> that I can fix them). How about an environment variable that captures the
> user's preference?
Since git only runs the hooks on the merged changes when you pass
--no-commit to 'git merge', defaulting to non-blind merge doesn't
really work anyway. There I propose the opposite default, as in the
attached (also you had a copy-pasto "; done" in your patch).
[-- Attachment #2: v2-0001-Allow-bypassing-of-some-checks-when-merging.patch --]
[-- Type: text/x-patch, Size: 2838 bytes --]
From 824e1bac7de365708e92e22b5aa2624e6bf7bd9e Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@Penguin.CS.UCLA.EDU>
Date: Wed, 12 Apr 2017 11:24:41 -0700
Subject: [PATCH v2] Allow bypassing of some checks when merging
* build-aux/git-hooks/pre-commit: Don't check merged in changes unless
GIT_MERGE_CAREFULLY is true.
* admin/notes/repo: Explain how to use GIT_MERGE_CAREFULLY.
---
admin/notes/repo | 7 +++++++
build-aux/git-hooks/pre-commit | 22 +++++++++++++++++++---
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/admin/notes/repo b/admin/notes/repo
index 3ab3da7807..2416563f83 100644
--- a/admin/notes/repo
+++ b/admin/notes/repo
@@ -76,6 +76,13 @@ conflict by choosing either the master or branch version, then run
'make -C lisp autoloads' to update the md5sums to the correct master
value before committing.
+* Running git commit hooks on merged changes
+
+Normally git does not run the pre-commit hook on merged changes. In
+order to run the hooks on the branch being merged in, set the
+environment variable GIT_MERGE_CAREFULLY to 'true', and the
+'--no-commit' option to the 'git merge' call.
+
* Re-adding a file that has been removed from the repository
Let's suppose you've done:
diff --git a/build-aux/git-hooks/pre-commit b/build-aux/git-hooks/pre-commit
index 6483bfc6b3..59bff79df1 100755
--- a/build-aux/git-hooks/pre-commit
+++ b/build-aux/git-hooks/pre-commit
@@ -25,16 +25,32 @@ LC_ALL=
. git-sh-setup
+# Unless GIT_MERGE_CAREFULLY is 'true', then when doing a two-way merge,
+# ignore problems that came from the other side of the merge.
+head=HEAD
+if test -e "$GIT_DIR"/MERGE_HEAD && test "$GIT_MERGE_CAREFULLY" != true; then
+ merge_heads=`cat "$GIT_DIR"/MERGE_HEAD` || exit
+ for merge_head in $merge_heads; do
+ case $head in
+ HEAD) head=$merge_head;;
+ # For multi-head merges, there's no easy way to ignore merged in
+ # changes. But if you're doing multi-head merges, presumably
+ # you know how to handle any ensuing problems.
+ *) head=HEAD; break;;
+ esac
+ done
+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`
+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
+for new_name in `$git_diff $head`; do
case $new_name in
-* | */-*)
echo "$new_name: File name component begins with '-'."
@@ -53,4 +69,4 @@ nbadchars=
# tests so that trailing spaces are generated on the fly rather than
# being committed as source.
-exec git diff-index --check --cached HEAD --
+exec git diff-index --check --cached $head --
--
2.11.1
next prev parent reply other threads:[~2017-04-29 18:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-11 16:25 git pre-commit hook for merges (WAS: master has switched from Automake to GNU Make) Noam Postavsky
2017-04-12 9:30 ` martin rudalics
2017-04-12 18:26 ` Paul Eggert
2017-04-13 0:13 ` Noam Postavsky
2017-04-13 1:49 ` Paul Eggert
2017-04-13 2:05 ` Noam Postavsky
2017-04-13 6:11 ` Paul Eggert
2017-04-13 20:04 ` Noam Postavsky
2017-04-29 18:00 ` Noam Postavsky [this message]
2017-04-29 18:44 ` Paul Eggert
2017-04-29 19:15 ` Eli Zaretskii
2017-04-29 19:54 ` Noam Postavsky
2017-04-29 20:04 ` Eli Zaretskii
2017-04-29 23:25 ` Noam Postavsky
2017-04-30 2:34 ` Eli Zaretskii
2017-04-30 19:35 ` Noam Postavsky
2017-04-30 19:40 ` Eli Zaretskii
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=CAM-tV-8-QnWDJ04cQXt1jPr-ufrZ6X4p7yTNmrsS7aJ5HrSKWw@mail.gmail.com \
--to=npostavs@users.sourceforge.net \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=rudalics@gmx.at \
--cc=schwab@suse.de \
--cc=yuri.v.khan@gmail.com \
/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.