git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] builtin/merge: honor commit-msg hook for merges
@ 2017-09-05 21:01 Stefan Beller
  2017-09-05 21:38 ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Beller @ 2017-09-05 21:01 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller

Similar to 65969d43d1 (merge: honor prepare-commit-msg hook, 2011-02-14)
merge should also honor the commit-msg hook; the reason is the same as
in that commit: When a merge is stopped due to conflicts or --no-commit,
the subsequent commit calls the commit-msg hook.  However, it is not
called after a clean merge. Fix this inconsistency by invoking the hook
after clean merges as well.

This change is motivated by Gerrits commit-msg hook to install a change-id
trailer into the commit message. Without such a change id, Gerrit refuses
to accept (merge) commits by default, such that the inconsistency of
(not) running commit-msg hook between commit and merge leads to confusion
and might block people from getting their work done.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/merge.c            |  8 ++++++++
 t/t7504-commit-msg-hook.sh | 45 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index 7df3fe3927..087efd560d 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -73,6 +73,7 @@ static int show_progress = -1;
 static int default_to_upstream = 1;
 static int signoff;
 static const char *sign_commit;
+static int no_verify;
 
 static struct strategy all_strategy[] = {
 	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -236,6 +237,7 @@ static struct option builtin_merge_options[] = {
 	  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 	OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
 	OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
+	OPT_BOOL(0, "no-verify", &no_verify, N_("bypass pre-commit and commit-msg hooks")),
 	OPT_END()
 };
 
@@ -780,6 +782,12 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 		if (launch_editor(git_path_merge_msg(), NULL, NULL))
 			abort_commit(remoteheads, NULL);
 	}
+
+	if (!no_verify && run_commit_hook(0 < option_edit, get_index_file(),
+					  "commit-msg",
+					  git_path_merge_msg(), NULL))
+		abort_commit(remoteheads, NULL);
+
 	read_merge_msg(&msg);
 	strbuf_stripspace(&msg, 0 < option_edit);
 	if (!msg.len)
diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh
index 88d4cda299..1cd54af3cc 100755
--- a/t/t7504-commit-msg-hook.sh
+++ b/t/t7504-commit-msg-hook.sh
@@ -101,6 +101,10 @@ cat > "$HOOK" <<EOF
 exit 1
 EOF
 
+commit_msg_is () {
+	test "$(git log --pretty=format:%s%b -1)" = "$1"
+}
+
 test_expect_success 'with failing hook' '
 
 	echo "another" >> file &&
@@ -135,6 +139,32 @@ test_expect_success '--no-verify with failing hook (editor)' '
 
 '
 
+test_expect_success 'merge fails with failing hook' '
+
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	test_must_fail git merge --allow-unrelated-histories master &&
+	commit_msg_is "in-side-branch" # HEAD before merge
+
+'
+
+test_expect_success 'merge bypasses failing hook with --no-verify' '
+
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	git merge --no-verify --allow-unrelated-histories master &&
+	commit_msg_is "Merge branch '\''master'\'' into newbranch"
+'
+
+
 chmod -x "$HOOK"
 test_expect_success POSIXPERM 'with non-executable hook' '
 
@@ -178,10 +208,6 @@ exit 0
 EOF
 chmod +x "$HOOK"
 
-commit_msg_is () {
-	test "$(git log --pretty=format:%s%b -1)" = "$1"
-}
-
 test_expect_success 'hook edits commit message' '
 
 	echo "additional" >> file &&
@@ -217,7 +243,17 @@ test_expect_success "hook doesn't edit commit message (editor)" '
 	echo "more plus" > FAKE_MSG &&
 	GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
 	commit_msg_is "more plus"
+'
 
+test_expect_success 'hook called in git-merge picks up commit message' '
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	git merge --allow-unrelated-histories master &&
+	commit_msg_is "new message"
 '
 
 # set up fake editor to replace `pick` by `reword`
@@ -237,4 +273,5 @@ test_expect_success 'hook is called for reword during `rebase -i`' '
 
 '
 
+
 test_done
-- 
2.14.0.rc0.3.g6c2e499285


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] builtin/merge: honor commit-msg hook for merges
  2017-09-05 21:01 [PATCH] builtin/merge: honor commit-msg hook for merges Stefan Beller
@ 2017-09-05 21:38 ` Junio C Hamano
  2017-09-05 23:08   ` [PATCH] parse-options: warn developers on negated options Stefan Beller
                     ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Junio C Hamano @ 2017-09-05 21:38 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

Stefan Beller <sbeller@google.com> writes:

> Similar to 65969d43d1 (merge: honor prepare-commit-msg hook, 2011-02-14)
> merge should also honor the commit-msg hook; the reason is the same as
> in that commit: When a merge is stopped due to conflicts or --no-commit,
> the subsequent commit calls the commit-msg hook.  However, it is not
> called after a clean merge. Fix this inconsistency by invoking the hook
> after clean merges as well.

The above reads better without "; the reason is the same as in that
commit"---"Similar to", combined with the clean and concise
explanation after the colon you have, sufficiently justifies why
this is a good change.  

Excellent job spotting the precedent and making it consistent ;-).

> This change is motivated by Gerrits commit-msg hook to install a change-id

s/Gerrits/Gerrit's/ perhaps?

> trailer into the commit message. Without such a change id, Gerrit refuses

I do not live in Gerrit land and I do not know which one is the more
preferred one, but be consistent between "change-id" and "change
id".

> to accept (merge) commits by default, such that the inconsistency of
> (not) running commit-msg hook between commit and merge leads to confusion
> and might block people from getting their work done.

Yup.  Nicely explained.

I didn't check how "merge --continue" is implemented, but we need to
behave exactly the same way over there, too.  Making sure that it is
a case in t7504 may be a good idea, in addition to the test you
added.

> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  builtin/merge.c            |  8 ++++++++
>  t/t7504-commit-msg-hook.sh | 45 +++++++++++++++++++++++++++++++++++++++++----
>  2 files changed, 49 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/merge.c b/builtin/merge.c
> index 7df3fe3927..087efd560d 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -73,6 +73,7 @@ static int show_progress = -1;
>  static int default_to_upstream = 1;
>  static int signoff;
>  static const char *sign_commit;
> +static int no_verify;
>  
>  static struct strategy all_strategy[] = {
>  	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
> @@ -236,6 +237,7 @@ static struct option builtin_merge_options[] = {
>  	  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
>  	OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
>  	OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
> +	OPT_BOOL(0, "no-verify", &no_verify, N_("bypass pre-commit and commit-msg hooks")),

This allows "--no-no-verify", which may want to be eventually
addressed (either by changing the code not to accept, or declaring
that it is an intended behaviour); I do not offhand know for sure but I
strong suspect "commit" shares the same issue, in which case this
patch is perfectly fine and addressing "--no-no-verify" should be
done for both of them in a separate follow-up topic.  #leftoverbits

Thanks.  I'll be online starting today, but please expect slow
responses for a few days as there is significant backlog.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] parse-options: warn developers on negated options
  2017-09-05 21:38 ` Junio C Hamano
@ 2017-09-05 23:08   ` Stefan Beller
  2017-09-06  1:52     ` Junio C Hamano
  2017-09-05 23:29   ` [PATCHv2] builtin/merge: honor commit-msg hook for merges Stefan Beller
  2017-09-07 22:04   ` [PATCHv3] " Stefan Beller
  2 siblings, 1 reply; 19+ messages in thread
From: Stefan Beller @ 2017-09-05 23:08 UTC (permalink / raw)
  To: gitster; +Cc: git, sbeller

When compiling with -DDEVELOPER set (enabled via the Makefile DEVELOPER
switch), inspect options if they are negated and warn about them.

 1. Negated options are usually are problem down the maintenance road:
    When a new negated option ("--no-foo") is introduced, then the option
    can be negated at run time("--no-no-foo"), which is usually confusing
    for boolean options.
 2. The handling of negated values (specifically double negations), usually
    require more brain power to get it right. In code that we own, we
    should strive to avoid double negatives ("!no_foo").

Signed-off-by: Stefan Beller <sbeller@google.com>
---

  #leftoverbits
  
  I was wondering if such a patch may be of value eventually (after all
  occurrences of "no-" options are fixed).
  This patch disallows all no- options, but we could be more open and allow
  --no-options that have the NO_NEG bit set.

 Makefile        | 3 ++-
 parse-options.c | 6 ++++++
 parse-options.h | 7 +++++--
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index aba0f5a0f9..9b87093f99 100644
--- a/Makefile
+++ b/Makefile
@@ -433,7 +433,8 @@ DEVELOPER_CFLAGS = -Werror \
 	-Wpointer-arith \
 	-Wstrict-prototypes \
 	-Wunused \
-	-Wvla
+	-Wvla \
+	-DDEVELOPER
 LDFLAGS =
 ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
diff --git a/parse-options.c b/parse-options.c
index 0dd9fc6a0d..08db926adf 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -403,6 +403,12 @@ static void parse_options_check(const struct option *opts)
 		if (opts->argh &&
 		    strcspn(opts->argh, " _") != strlen(opts->argh))
 			err |= optbug(opts, "multi-word argh should use dash to separate words");
+#if DEVELOPER
+		if ((opts->flags & PARSE_OPT_ERR_NEGATED) &&
+		    !strcmp("no-", opts->long_name))
+			BUG("Get %s fixed! double negation possible",
+			    opts->long_name);
+#endif
 	}
 	if (err)
 		exit(128);
diff --git a/parse-options.h b/parse-options.h
index af711227ae..9dc07fd9bb 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -38,7 +38,8 @@ enum parse_opt_option_flags {
 	PARSE_OPT_LASTARG_DEFAULT = 16,
 	PARSE_OPT_NODASH = 32,
 	PARSE_OPT_LITERAL_ARGHELP = 64,
-	PARSE_OPT_SHELL_EVAL = 256
+	PARSE_OPT_SHELL_EVAL = 256,
+	PARSE_OPT_ERR_NEGATED = 512
 };
 
 struct option;
@@ -124,7 +125,9 @@ struct option {
 				      (h), PARSE_OPT_NOARG }
 #define OPT_SET_INT(s, l, v, h, i)  { OPTION_SET_INT, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG, NULL, (i) }
-#define OPT_BOOL(s, l, v, h)        OPT_SET_INT(s, l, v, h, 1)
+#define OPT_BOOL(s, l, v, h)        { OPTION_SET_INT, (s), (l), (v), NULL, \
+				      (h), PARSE_OPT_NOARG|PARSE_OPT_ERR_NEGATED, \
+				      NULL, 1 }
 #define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
 #define OPT_CMDMODE(s, l, v, h, i)  { OPTION_CMDMODE, (s), (l), (v), NULL, \
-- 
2.14.0.rc0.3.g6c2e499285


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCHv2] builtin/merge: honor commit-msg hook for merges
  2017-09-05 21:38 ` Junio C Hamano
  2017-09-05 23:08   ` [PATCH] parse-options: warn developers on negated options Stefan Beller
@ 2017-09-05 23:29   ` Stefan Beller
  2017-09-06  1:57     ` Junio C Hamano
  2017-09-07 22:04   ` [PATCHv3] " Stefan Beller
  2 siblings, 1 reply; 19+ messages in thread
From: Stefan Beller @ 2017-09-05 23:29 UTC (permalink / raw)
  To: gitster; +Cc: git, sbeller

Similar to 65969d43d1 (merge: honor prepare-commit-msg hook, 2011-02-14)
merge should also honor the commit-msg hook: When a merge is stopped due
to conflicts or --no-commit, the subsequent commit calls the commit-msg
hook.  However, it is not called after a clean merge. Fix this
inconsistency by invoking the hook after clean merges as well.

This change is motivated by Gerrit's commit-msg hook to install a ChangeId
trailer into the commit message. Without such a ChangeId, Gerrit refuses
to accept any commit by default, such that the inconsistency of (not)
running the commit-msg hook between commit and merge leads to confusion
and might block people from getting their work done.

As the githooks man page is very vocal about the possibility of skipping
the commit-msg hook via the --no-verify option, implement the option
in merge, too.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

addressed all but one issues.

Junio writes:
> I didn't check how "merge --continue" is implemented, but we need to
> behave exactly the same way over there, too.  Making sure that it is
> a case in t7504 may be a good idea, in addition to the test you
> added.

After inspection of the code I do not think it is a good idea, because
(a) it clutters the test suite with something "obvious" for now,
    the call to cmd_commit will be the same as git-commit on the
    command line and
(b) piping through --[no-]verify would either introduce irregularities
    ("Why do we pipe through --no-verify, when --sign-off is more important?")
    or miss important options to pipe through: 

	static int continue_current_merge;
...
	OPT_BOOL(0, "continue", &continue_current_merge,
		N_("continue the current in-progress merge")),
...
	if (continue_current_merge) {
		int nargc = 1;
		const char *nargv[] = {"commit", NULL};

		if (orig_argc != 2)
			usage_msg_opt(_("--continue expects no arguments"),
			      builtin_merge_usage, builtin_merge_options);

		/* Invoke 'git commit' */
		ret = cmd_commit(nargc, nargv, prefix);
		goto done;
	}

Thanks,
Stefan

 builtin/merge.c            |  8 ++++++++
 t/t7504-commit-msg-hook.sh | 45 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index 7df3fe3927..780435d7a1 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -73,6 +73,7 @@ static int show_progress = -1;
 static int default_to_upstream = 1;
 static int signoff;
 static const char *sign_commit;
+static int verify_msg = 1;
 
 static struct strategy all_strategy[] = {
 	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -236,6 +237,7 @@ static struct option builtin_merge_options[] = {
 	  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 	OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
 	OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
+	OPT_BOOL(0, "verify", &verify_msg, N_("verify commit-msg hook")),
 	OPT_END()
 };
 
@@ -780,6 +782,12 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 		if (launch_editor(git_path_merge_msg(), NULL, NULL))
 			abort_commit(remoteheads, NULL);
 	}
+
+	if (verify_msg && run_commit_hook(0 < option_edit, get_index_file(),
+					  "commit-msg",
+					  git_path_merge_msg(), NULL))
+		abort_commit(remoteheads, NULL);
+
 	read_merge_msg(&msg);
 	strbuf_stripspace(&msg, 0 < option_edit);
 	if (!msg.len)
diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh
index 88d4cda299..1cd54af3cc 100755
--- a/t/t7504-commit-msg-hook.sh
+++ b/t/t7504-commit-msg-hook.sh
@@ -101,6 +101,10 @@ cat > "$HOOK" <<EOF
 exit 1
 EOF
 
+commit_msg_is () {
+	test "$(git log --pretty=format:%s%b -1)" = "$1"
+}
+
 test_expect_success 'with failing hook' '
 
 	echo "another" >> file &&
@@ -135,6 +139,32 @@ test_expect_success '--no-verify with failing hook (editor)' '
 
 '
 
+test_expect_success 'merge fails with failing hook' '
+
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	test_must_fail git merge --allow-unrelated-histories master &&
+	commit_msg_is "in-side-branch" # HEAD before merge
+
+'
+
+test_expect_success 'merge bypasses failing hook with --no-verify' '
+
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	git merge --no-verify --allow-unrelated-histories master &&
+	commit_msg_is "Merge branch '\''master'\'' into newbranch"
+'
+
+
 chmod -x "$HOOK"
 test_expect_success POSIXPERM 'with non-executable hook' '
 
@@ -178,10 +208,6 @@ exit 0
 EOF
 chmod +x "$HOOK"
 
-commit_msg_is () {
-	test "$(git log --pretty=format:%s%b -1)" = "$1"
-}
-
 test_expect_success 'hook edits commit message' '
 
 	echo "additional" >> file &&
@@ -217,7 +243,17 @@ test_expect_success "hook doesn't edit commit message (editor)" '
 	echo "more plus" > FAKE_MSG &&
 	GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
 	commit_msg_is "more plus"
+'
 
+test_expect_success 'hook called in git-merge picks up commit message' '
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	git merge --allow-unrelated-histories master &&
+	commit_msg_is "new message"
 '
 
 # set up fake editor to replace `pick` by `reword`
@@ -237,4 +273,5 @@ test_expect_success 'hook is called for reword during `rebase -i`' '
 
 '
 
+
 test_done
-- 
2.14.0.rc0.3.g6c2e499285


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] parse-options: warn developers on negated options
  2017-09-05 23:08   ` [PATCH] parse-options: warn developers on negated options Stefan Beller
@ 2017-09-06  1:52     ` Junio C Hamano
  2017-09-06  3:16       ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2017-09-06  1:52 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

Stefan Beller <sbeller@google.com> writes:

>   This patch disallows all no- options, but we could be more open and allow
>   --no-options that have the NO_NEG bit set.

"--no-foo" that does not take "--foo" is perhaps OK so should not
trigger an error.

A ("--no-foo", "--foo") pair is better spelled as ("--foo",
"--no-foo") pair whose default is "--foo", but making it an error is
probably a bit too much.

Compared to that, ("--no-foo", "--no-no-foo") pair feels nonsense.

Having said that, because the existing parse_options_check() is all
about catching the programming mistake (the end user cannot fix an
error from it by tweaking the command line option s/he gives to the
program), I do not think a conditional compilation like you added
mixes well.  Either make the whole thing, not just your new test,
conditional to -DDEVELOPER (which would make it possible for you to
build and ship a binary with broken options[] array to the end-users
that does not die in this function), which is undesirable, or add a
new test that catches a definite error unconditionally.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCHv2] builtin/merge: honor commit-msg hook for merges
  2017-09-05 23:29   ` [PATCHv2] builtin/merge: honor commit-msg hook for merges Stefan Beller
@ 2017-09-06  1:57     ` Junio C Hamano
  2017-09-06 22:11       ` Stefan Beller
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2017-09-06  1:57 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

Stefan Beller <sbeller@google.com> writes:

> Junio writes:
>> I didn't check how "merge --continue" is implemented, but we need to
>> behave exactly the same way over there, too.  Making sure that it is
>> a case in t7504 may be a good idea, in addition to the test you
>> added.
>
> After inspection of the code I do not think it is a good idea, because
> (a) it clutters the test suite with something "obvious" for now,
>     the call to cmd_commit will be the same as git-commit on the
>     command line and
> (b) piping through --[no-]verify would either introduce irregularities
>     ("Why do we pipe through --no-verify, when --sign-off is more important?")
>     or miss important options to pipe through: 
>
> 	static int continue_current_merge;
> ...
> 	OPT_BOOL(0, "continue", &continue_current_merge,
> 		N_("continue the current in-progress merge")),
> ...
> 	if (continue_current_merge) {
> 		int nargc = 1;
> 		const char *nargv[] = {"commit", NULL};
>
> 		if (orig_argc != 2)
> 			usage_msg_opt(_("--continue expects no arguments"),
> 			      builtin_merge_usage, builtin_merge_options);
>
> 		/* Invoke 'git commit' */
> 		ret = cmd_commit(nargc, nargv, prefix);
> 		goto done;
> 	}

That line of thought is backwards.  'something "obvious" for now'
talks about the present.  tests are all about future-proofing.

I also thought that we were hunting calls of cmd_foo() from outside
the git.c command dispatcher as grave errors and want to clean up
the codebase to get rid of them.  So the above is the worst example
to use when you are trying to convince why it needs no test---the
above is a good example of the code that would need to change soon
when we have enough volunteers willing to keep the codebase clean
and healthy, and we would benefit from future-proofing tests.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] parse-options: warn developers on negated options
  2017-09-06  1:52     ` Junio C Hamano
@ 2017-09-06  3:16       ` Junio C Hamano
  2017-09-06 21:36         ` Stefan Beller
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2017-09-06  3:16 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Stefan Beller <sbeller@google.com> writes:
>
>>   This patch disallows all no- options, but we could be more open and allow
>>   --no-options that have the NO_NEG bit set.
>
> "--no-foo" that does not take "--foo" is perhaps OK so should not
> trigger an error.
>
> A ("--no-foo", "--foo") pair is better spelled as ("--foo",
> "--no-foo") pair whose default is "--foo", but making it an error is
> probably a bit too much.
>
> Compared to that, ("--no-foo", "--no-no-foo") pair feels nonsense.

Ahh, I was an idiot (call it vacation-induced-brain-disfunction).  I
forgot about 0f1930c5 ("parse-options: allow positivation of options
starting, with no-", 2012-02-25), which may have already made your
new use of "--no-verify" in builtin/merge.c and existing one in
commit.c OK long time ago.  A quick check to see how your version of

	git merge --verify
	git merge --no-verify

behaves with respect to the commit-msg hook is veriy much
appreciated, as my tree is in no shape to apply and try a patch
while trying to absorb the patches sent to the list the past week.

Thanks, and sorry for a possible false alarm.

> Having said that, because the existing parse_options_check() is all
> about catching the programming mistake (the end user cannot fix an
> error from it by tweaking the command line option s/he gives to the
> program), I do not think a conditional compilation like you added
> mixes well.  Either make the whole thing, not just your new test,
> conditional to -DDEVELOPER (which would make it possible for you to
> build and ship a binary with broken options[] array to the end-users
> that does not die in this function), which is undesirable, or add a
> new test that catches a definite error unconditionally.

This part still is valid.  If René's work 2 years ago is sufficient
to address "--no-foo" thing, then there is nothing we need to add to
this test, but if we later need to add new sanity check, we should
add it without -DDEVELOPER, or we should make the whole thing inside
it.

Thanks.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] parse-options: warn developers on negated options
  2017-09-06  3:16       ` Junio C Hamano
@ 2017-09-06 21:36         ` Stefan Beller
  2017-09-06 23:41           ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Beller @ 2017-09-06 21:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

On Tue, Sep 5, 2017 at 8:16 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Stefan Beller <sbeller@google.com> writes:
>>
>>>   This patch disallows all no- options, but we could be more open and allow
>>>   --no-options that have the NO_NEG bit set.
>>
>> "--no-foo" that does not take "--foo" is perhaps OK so should not
>> trigger an error.
>>
>> A ("--no-foo", "--foo") pair is better spelled as ("--foo",
>> "--no-foo") pair whose default is "--foo", but making it an error is
>> probably a bit too much.
>>
>> Compared to that, ("--no-foo", "--no-no-foo") pair feels nonsense.
>
> Ahh, I was an idiot (call it vacation-induced-brain-disfunction).  I
> forgot about 0f1930c5 ("parse-options: allow positivation of options
> starting, with no-", 2012-02-25), which may have already made your
> new use of "--no-verify" in builtin/merge.c and existing one in
> commit.c OK long time ago.  A quick check to see how your version of
>
>         git merge --verify
>         git merge --no-verify
>
> behaves with respect to the commit-msg hook is veriy much
> appreciated, as my tree is in no shape to apply and try a patch
> while trying to absorb the patches sent to the list the past week.
>
> Thanks, and sorry for a possible false alarm.
>
>> Having said that, because the existing parse_options_check() is all
>> about catching the programming mistake (the end user cannot fix an
>> error from it by tweaking the command line option s/he gives to the
>> program), I do not think a conditional compilation like you added
>> mixes well.  Either make the whole thing, not just your new test,
>> conditional to -DDEVELOPER (which would make it possible for you to
>> build and ship a binary with broken options[] array to the end-users
>> that does not die in this function), which is undesirable, or add a
>> new test that catches a definite error unconditionally.
>
> This part still is valid.  If René's work 2 years ago is sufficient
> to address "--no-foo" thing, then there is nothing we need to add to
> this test, but if we later need to add new sanity check, we should
> add it without -DDEVELOPER, or we should make the whole thing inside
> it.

As far as the code is concerned it is only inside the -DDEVELOPER ?
The intent of this patch is to have a developers aid to remind them
that too many negations might be a sign of trouble.

Thanks,
Stefan

>
> Thanks.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCHv2] builtin/merge: honor commit-msg hook for merges
  2017-09-06  1:57     ` Junio C Hamano
@ 2017-09-06 22:11       ` Stefan Beller
  2017-09-06 23:43         ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Beller @ 2017-09-06 22:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

On Tue, Sep 5, 2017 at 6:57 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> Junio writes:
>>> I didn't check how "merge --continue" is implemented, but we need to
>>> behave exactly the same way over there, too.  Making sure that it is
>>> a case in t7504 may be a good idea, in addition to the test you
>>> added.
>>
>> After inspection of the code I do not think it is a good idea, because
>> (a) it clutters the test suite with something "obvious" for now,
>>     the call to cmd_commit will be the same as git-commit on the
>>     command line and
>> (b) piping through --[no-]verify would either introduce irregularities
>>     ("Why do we pipe through --no-verify, when --sign-off is more important?")
>>     or miss important options to pipe through:
>>
>>       static int continue_current_merge;
>> ...
>>       OPT_BOOL(0, "continue", &continue_current_merge,
>>               N_("continue the current in-progress merge")),
>> ...
>>       if (continue_current_merge) {
>>               int nargc = 1;
>>               const char *nargv[] = {"commit", NULL};
>>
>>               if (orig_argc != 2)
>>                       usage_msg_opt(_("--continue expects no arguments"),
>>                             builtin_merge_usage, builtin_merge_options);
>>
>>               /* Invoke 'git commit' */
>>               ret = cmd_commit(nargc, nargv, prefix);
>>               goto done;
>>       }
>
> That line of thought is backwards.  'something "obvious" for now'
> talks about the present.  tests are all about future-proofing.

I agree, but I did not think a call to cmd_commit would need to
be future-proofed as we already test git-commit, and these
are equal....

>
> I also thought that we were hunting calls of cmd_foo() from outside
> the git.c command dispatcher as grave errors and want to clean up
> the codebase to get rid of them.

... but I did not account for this fact. (I was not aware of these being
called grave errors, but assumed this is a good state. And why change
a good state?)

> So the above is the worst example
> to use when you are trying to convince why it needs no test---the
> above is a good example of the code that would need to change soon
> when we have enough volunteers willing to keep the codebase clean
> and healthy, and we would benefit from future-proofing tests.

Given that new fact, I agree with the reasoning to add a new test
for future proofing. In the current form

    git merge --continue --no-verify

would trigger to usage_msg_opt(..), so all I'd offer is a test_must_fail
for now?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] parse-options: warn developers on negated options
  2017-09-06 21:36         ` Stefan Beller
@ 2017-09-06 23:41           ` Junio C Hamano
  0 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2017-09-06 23:41 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

>> Ahh, I was an idiot (call it vacation-induced-brain-disfunction).  I
>> forgot about 0f1930c5 ("parse-options: allow positivation of options
>> starting, with no-", 2012-02-25), which may have already made your
>> new use of "--no-verify" in builtin/merge.c and existing one in
>> commit.c OK long time ago.  A quick check to see how your version of
>>
>>         git merge --verify
>>         git merge --no-verify
>>
>> behaves with respect to the commit-msg hook is veriy much
>> appreciated, as my tree is in no shape to apply and try a patch
>> while trying to absorb the patches sent to the list the past week.
>>
>> Thanks, and sorry for a possible false alarm.
>>
>>> Having said that, because the existing parse_options_check() is all
>>> about catching the programming mistake (the end user cannot fix an
>>> error from it by tweaking the command line option s/he gives to the
>>> program), I do not think a conditional compilation like you added
>>> mixes well.  Either make the whole thing, not just your new test,
>>> conditional to -DDEVELOPER (which would make it possible for you to
>>> build and ship a binary with broken options[] array to the end-users
>>> that does not die in this function), which is undesirable, or add a
>>> new test that catches a definite error unconditionally.
>>
>> This part still is valid.  If René's work 2 years ago is sufficient
>> to address "--no-foo" thing, then there is nothing we need to add to
>> this test, but if we later need to add new sanity check, we should
>> add it without -DDEVELOPER, or we should make the whole thing inside
>> it.
>
> As far as the code is concerned it is only inside the -DDEVELOPER ?
> The intent of this patch is to have a developers aid to remind them
> that too many negations might be a sign of trouble.

I understand that.  What I was saying is that there may be no point
"reminding" them with René's "positivation" thing in effect and that
is why I asked you to try the simple two commands out to see if that
is the case.

I did that myself with "git commit --[no-]verify" and they are
indeed OK, so there is no reason to force developers to do this:

	int distim = 1; /* default is to distim */
	struct option options[] = {
		...
		OPT_BOOL(0, "distim", &distim, N_("distim")),
		...
	};
	...
	if (distim)
		do_the_distim_thing();

if/when the following is more natural in the context of the command:

	int no_distim = 1; /* default is to distim */
	struct option options[] = {
		...
		OPT_BOOL(0, "no-distim", &distim, N_("bypass distimming")),
		...
	};
	...
	if (distim)
		do_the_distim_thing();

whether it is inside -DDEVELOPER or not.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCHv2] builtin/merge: honor commit-msg hook for merges
  2017-09-06 22:11       ` Stefan Beller
@ 2017-09-06 23:43         ` Junio C Hamano
  0 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2017-09-06 23:43 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

>> I also thought that we were hunting calls of cmd_foo() from outside
>> the git.c command dispatcher as grave errors and want to clean up
>> the codebase to get rid of them.
>
> ... but I did not account for this fact. (I was not aware of these being
> called grave errors, but assumed this is a good state. And why change
> a good state?)

https://public-inbox.org/git/20170830053108.g2xsn43rwulnwn3p@sigill.intra.peff.net/

gives a good explanation why it is not a good state.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCHv3] builtin/merge: honor commit-msg hook for merges
  2017-09-05 21:38 ` Junio C Hamano
  2017-09-05 23:08   ` [PATCH] parse-options: warn developers on negated options Stefan Beller
  2017-09-05 23:29   ` [PATCHv2] builtin/merge: honor commit-msg hook for merges Stefan Beller
@ 2017-09-07 22:04   ` Stefan Beller
  2017-09-08  1:13     ` Junio C Hamano
  2017-09-16  6:22     ` Kaartic Sivaraam
  2 siblings, 2 replies; 19+ messages in thread
From: Stefan Beller @ 2017-09-07 22:04 UTC (permalink / raw)
  To: gitster; +Cc: git, sbeller

Similar to 65969d43d1 (merge: honor prepare-commit-msg hook, 2011-02-14)
merge should also honor the commit-msg hook: When a merge is stopped due
to conflicts or --no-commit, the subsequent commit calls the commit-msg
hook.  However, it is not called after a clean merge. Fix this
inconsistency by invoking the hook after clean merges as well.

This change is motivated by Gerrit's commit-msg hook to install a ChangeId
trailer into the commit message. Without such a ChangeId, Gerrit refuses
to accept any commit by default, such that the inconsistency of (not)
running the commit-msg hook between commit and merge leads to confusion
and might block people from getting their work done.

As the githooks man page is very vocal about the possibility of skipping
the commit-msg hook via the --no-verify option, implement the option
in merge, too.

'git merge --continue' is currently implemented as calling cmd_commit
with no further arguments. This works for most other merge related options,
such as demonstrated via the --allow-unrelated-histories flag in the
test. The --no-verify option however is not remembered across invocations
of git-merge. Originally the author assumed an alternative in which the
'git merge --continue' command accepts the --no-verify flag, but that
opens up the discussion which flags are allows to the continued merge
command and which must be given in the first invocation.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

> I didn't check how "merge --continue" is implemented, but we need to
> behave exactly the same way over there, too.  Making sure that it is
> a case in t7504 may be a good idea, in addition to the test you
> added.

First I understood this as if we'd want to support
'git merge --continue --no-verify' eventually, but by now I think we want
to 'carry over' the meaning from the first invocation of git-merge.

For that I added a test.

Thanks,
Stefan

 builtin/merge.c            |  8 ++++++
 t/t7504-commit-msg-hook.sh | 64 +++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index 7df3fe3927..780435d7a1 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -73,6 +73,7 @@ static int show_progress = -1;
 static int default_to_upstream = 1;
 static int signoff;
 static const char *sign_commit;
+static int verify_msg = 1;
 
 static struct strategy all_strategy[] = {
 	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -236,6 +237,7 @@ static struct option builtin_merge_options[] = {
 	  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
 	OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
 	OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
+	OPT_BOOL(0, "verify", &verify_msg, N_("verify commit-msg hook")),
 	OPT_END()
 };
 
@@ -780,6 +782,12 @@ static void prepare_to_commit(struct commit_list *remoteheads)
 		if (launch_editor(git_path_merge_msg(), NULL, NULL))
 			abort_commit(remoteheads, NULL);
 	}
+
+	if (verify_msg && run_commit_hook(0 < option_edit, get_index_file(),
+					  "commit-msg",
+					  git_path_merge_msg(), NULL))
+		abort_commit(remoteheads, NULL);
+
 	read_merge_msg(&msg);
 	strbuf_stripspace(&msg, 0 < option_edit);
 	if (!msg.len)
diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh
index 88d4cda299..302a3a2082 100755
--- a/t/t7504-commit-msg-hook.sh
+++ b/t/t7504-commit-msg-hook.sh
@@ -101,6 +101,10 @@ cat > "$HOOK" <<EOF
 exit 1
 EOF
 
+commit_msg_is () {
+	test "$(git log --pretty=format:%s%b -1)" = "$1"
+}
+
 test_expect_success 'with failing hook' '
 
 	echo "another" >> file &&
@@ -135,6 +139,32 @@ test_expect_success '--no-verify with failing hook (editor)' '
 
 '
 
+test_expect_success 'merge fails with failing hook' '
+
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	test_must_fail git merge --allow-unrelated-histories master &&
+	commit_msg_is "in-side-branch" # HEAD before merge
+
+'
+
+test_expect_success 'merge bypasses failing hook with --no-verify' '
+
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	git merge --no-verify --allow-unrelated-histories master &&
+	commit_msg_is "Merge branch '\''master'\'' into newbranch"
+'
+
+
 chmod -x "$HOOK"
 test_expect_success POSIXPERM 'with non-executable hook' '
 
@@ -178,10 +208,6 @@ exit 0
 EOF
 chmod +x "$HOOK"
 
-commit_msg_is () {
-	test "$(git log --pretty=format:%s%b -1)" = "$1"
-}
-
 test_expect_success 'hook edits commit message' '
 
 	echo "additional" >> file &&
@@ -217,7 +243,36 @@ test_expect_success "hook doesn't edit commit message (editor)" '
 	echo "more plus" > FAKE_MSG &&
 	GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
 	commit_msg_is "more plus"
+'
 
+test_expect_success 'hook called in git-merge picks up commit message' '
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout --orphan newbranch &&
+	: >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	git merge --allow-unrelated-histories master &&
+	commit_msg_is "new message"
+'
+
+test_expect_failure 'merge --continue remembers --no-verify' '
+	test_when_finished "git branch -D newbranch" &&
+	test_when_finished "git checkout -f master" &&
+	git checkout master &&
+	echo a >file2 &&
+	git add file2 &&
+	git commit --no-verify -m "add file2 to master" &&
+	git checkout -b newbranch master^ &&
+	echo b >file2 &&
+	git add file2 &&
+	git commit --no-verify file2 -m in-side-branch &&
+	git merge --no-verify -m not-rewritten-by-hook master &&
+	# resolve conflict:
+	echo c >file2 &&
+	git add file2 &&
+	git merge --continue &&
+	commit_msg_is not-rewritten-by-hook
 '
 
 # set up fake editor to replace `pick` by `reword`
@@ -237,4 +292,5 @@ test_expect_success 'hook is called for reword during `rebase -i`' '
 
 '
 
+
 test_done
-- 
2.14.0.rc0.3.g6c2e499285


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCHv3] builtin/merge: honor commit-msg hook for merges
  2017-09-07 22:04   ` [PATCHv3] " Stefan Beller
@ 2017-09-08  1:13     ` Junio C Hamano
  2017-09-11 17:12       ` Stefan Beller
  2017-09-16  6:22     ` Kaartic Sivaraam
  1 sibling, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2017-09-08  1:13 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

Stefan Beller <sbeller@google.com> writes:

> .... The --no-verify option however is not remembered across invocations
> of git-merge. Originally the author assumed an alternative in which the
> 'git merge --continue' command accepts the --no-verify flag, but that
> opens up the discussion which flags are allows to the continued merge
> command and which must be given in the first invocation.

This leaves a reader (me) wondering what the final conclusion was,
after the author assumed something and thought about alternatives.
I am guessing that your final decision was not to remember
"--no-verify" so a user who started "merge --no-verify" that stopped
in the middle must say "merge --continue --no-verify" or "commit
--no-verify" to conclude the merge?  Or you added some mechanism to
remember the fact that no-verify was given so that "merge --continue"
will read from there, ignoring "merge --continue --verify" from the
command line?  Not just the above part of the log message confusing,
but there is no update to the documentation, and we shouldn't expect
end-users to find out what ought to happen by reading t7504 X-<.

The new test in t7504 tells me that you remember --[no-]verify from
the initial invocation and use the same when --continue is given; it
is unclear how that remembered one interacts with --[no-]verify that
is given when --continue is given.  It is not documented, tested and
explained in the log message.  I would expect that the command line 
trumps what was given in the initial invocation.


> +static int verify_msg = 1;
>  
>  static struct strategy all_strategy[] = {
>  	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
> @@ -236,6 +237,7 @@ static struct option builtin_merge_options[] = {
>  	  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
>  	OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
>  	OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
> +	OPT_BOOL(0, "verify", &verify_msg, N_("verify commit-msg hook")),
>  	OPT_END()
>  };

I suspect that the previous iteration gives a much better end-user
experience when "git merge -h" is used.  This will give the
impression that the user MUST say "merge --verify" if the user wants
to verify commit-msg hook (whatever that means), but because the
option defaults to true, that is not what happens.  The user instead
must say "merge --no-verify" if the verification is unwanted.

"git commit -h" explains 

    --no-verify        bypass pre-commit and commit-msg hooks

and I think that is the way how we want to explain this option in
"git merge" too.  Normally it is not bypassed, and the user can ask
with "--no-verify".  Thanks to René's change in 2012, the option
definition you had in the previous one will make --[no-]verify
accepted just fine.

> +test_expect_success 'merge fails with failing hook' '
> + ...
> +'
> +
> +test_expect_success 'merge bypasses failing hook with --no-verify' '
> + ...
> +'

Both look sensible.

> +test_expect_failure 'merge --continue remembers --no-verify' '
> +	test_when_finished "git branch -D newbranch" &&
> +	test_when_finished "git checkout -f master" &&
> +	git checkout master &&
> +	echo a >file2 &&
> +	git add file2 &&
> +	git commit --no-verify -m "add file2 to master" &&
> +	git checkout -b newbranch master^ &&
> +	echo b >file2 &&
> +	git add file2 &&
> +	git commit --no-verify file2 -m in-side-branch &&
> +	git merge --no-verify -m not-rewritten-by-hook master &&
> +	# resolve conflict:
> +	echo c >file2 &&
> +	git add file2 &&
> +	git merge --continue &&
> +	commit_msg_is not-rewritten-by-hook
>  '

OK.  What should happen when the last "merge --continue" was given
"--verify" at the same time?  A similar test whose title is
"--no-verify remembered by merge --continue can be overriden" may be
a good thing to follow this one, perhaps?

Thanks.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCHv3] builtin/merge: honor commit-msg hook for merges
  2017-09-08  1:13     ` Junio C Hamano
@ 2017-09-11 17:12       ` Stefan Beller
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Beller @ 2017-09-11 17:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

On Thu, Sep 7, 2017 at 6:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> .... The --no-verify option however is not remembered across invocations
>> of git-merge. Originally the author assumed an alternative in which the
>> 'git merge --continue' command accepts the --no-verify flag, but that
>> opens up the discussion which flags are allows to the continued merge
>> command and which must be given in the first invocation.
>
> This leaves a reader (me) wondering what the final conclusion was,
> after the author assumed something and thought about alternatives.

I did not draw a conclusion, I was just saying, that this has to be
thought about.
It looks to me as if --continue currently wants to take no extra arguments,
but to remember all flags from the previous invocation of merge.

But that only looks this way as all the command line flags are related
for tree manipulation, not (indirect) commit message manipulation.

So I think having --no-verify be respected (either by restating, or by
remembering, or both) by the `git merge --continue` call would be a
reasonable thing to want.

So that new patch just added the test as a #needswork for the future,
not actually making a decision how to approach it.

> I am guessing that your final decision was not to remember
> "--no-verify" so a user who started "merge --no-verify" that stopped
> in the middle must say "merge --continue --no-verify" or "commit
> --no-verify" to conclude the merge?  Or you added some mechanism to
> remember the fact that no-verify was given so that "merge --continue"
> will read from there, ignoring "merge --continue --verify" from the
> command line?  Not just the above part of the log message confusing,
> but there is no update to the documentation, and we shouldn't expect
> end-users to find out what ought to happen by reading t7504 X-<.

Interestingly the documentation that I read to approach the problem
is already in shape as it would not specify the specific command for the
'--no-verify' option. I missed that we need to add documentation for
the continued merge case.

> The new test in t7504 tells me that you remember --[no-]verify from
> the initial invocation and use the same when --continue is given; it
> is unclear how that remembered one interacts with --[no-]verify that
> is given when --continue is given.  It is not documented, tested and
> explained in the log message.  I would expect that the command line
> trumps what was given in the initial invocation.

I would expect that, too.

>
>
>> +static int verify_msg = 1;
>>
>>  static struct strategy all_strategy[] = {
>>       { "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
>> @@ -236,6 +237,7 @@ static struct option builtin_merge_options[] = {
>>         N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
>>       OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
>>       OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
>> +     OPT_BOOL(0, "verify", &verify_msg, N_("verify commit-msg hook")),
>>       OPT_END()
>>  };
>
> I suspect that the previous iteration gives a much better end-user
> experience when "git merge -h" is used.  This will give the
> impression that the user MUST say "merge --verify" if the user wants
> to verify commit-msg hook (whatever that means), but because the
> option defaults to true, that is not what happens.  The user instead
> must say "merge --no-verify" if the verification is unwanted.

ok, will revert to that in a resend.

>> +test_expect_failure 'merge --continue remembers --no-verify' '
>> +     test_when_finished "git branch -D newbranch" &&
>> +     test_when_finished "git checkout -f master" &&
>> +     git checkout master &&
>> +     echo a >file2 &&
>> +     git add file2 &&
>> +     git commit --no-verify -m "add file2 to master" &&
>> +     git checkout -b newbranch master^ &&
>> +     echo b >file2 &&
>> +     git add file2 &&
>> +     git commit --no-verify file2 -m in-side-branch &&
>> +     git merge --no-verify -m not-rewritten-by-hook master &&
>> +     # resolve conflict:
>> +     echo c >file2 &&
>> +     git add file2 &&
>> +     git merge --continue &&
>> +     commit_msg_is not-rewritten-by-hook
>>  '
>
> OK.  What should happen when the last "merge --continue" was given
> "--verify" at the same time?

Currently not possible, due to --continue requiring that it is the
only argument. In the future where --continue works well with other
arguments, we should override the original.

> A similar test whose title is
> "--no-verify remembered by merge --continue can be overriden" may be
> a good thing to follow this one, perhaps?

Note that this is already test_expect_failure, which I used to mark
that this particular flag is broken across a --continue invocation of git-merge,
so I would not add yet another test that describes the future yet to be
implemented?

Thanks.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCHv3] builtin/merge: honor commit-msg hook for merges
  2017-09-07 22:04   ` [PATCHv3] " Stefan Beller
  2017-09-08  1:13     ` Junio C Hamano
@ 2017-09-16  6:22     ` Kaartic Sivaraam
  2017-09-20 19:55       ` Stefan Beller
  2017-09-21 20:29       ` [PATCH] Documentation/githooks: mention merge in commit-msg hook Stefan Beller
  1 sibling, 2 replies; 19+ messages in thread
From: Kaartic Sivaraam @ 2017-09-16  6:22 UTC (permalink / raw)
  To: Stefan Beller, gitster; +Cc: git

Seems 'Documentation/githooks.txt' needs an update related to this
change. Previously it said(note the **s) that 'commit-msg' is invoked
only by 'git commit',

    commit-msg
           This hook is invoked by git commit**, and can be bypassed with the
           --no-verify option. It takes a single parameter, the name of the file
           that holds the proposed commit log message. Exiting with a non-zero
           status causes the git commit** to abort.

---
Kaartic

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCHv3] builtin/merge: honor commit-msg hook for merges
  2017-09-16  6:22     ` Kaartic Sivaraam
@ 2017-09-20 19:55       ` Stefan Beller
  2017-09-21  1:10         ` Junio C Hamano
  2017-09-21 20:29       ` [PATCH] Documentation/githooks: mention merge in commit-msg hook Stefan Beller
  1 sibling, 1 reply; 19+ messages in thread
From: Stefan Beller @ 2017-09-20 19:55 UTC (permalink / raw)
  To: Kaartic Sivaraam; +Cc: Junio C Hamano, git@vger.kernel.org

On Fri, Sep 15, 2017 at 11:22 PM, Kaartic Sivaraam
<kaarticsivaraam91196@gmail.com> wrote:
> Seems 'Documentation/githooks.txt' needs an update related to this
> change. Previously it said(note the **s) that 'commit-msg' is invoked
> only by 'git commit',
>
>     commit-msg
>            This hook is invoked by git commit**, and can be bypassed with the
>            --no-verify option. It takes a single parameter, the name of the file
>            that holds the proposed commit log message. Exiting with a non-zero
>            status causes the git commit** to abort.

Yes that needs an update. When writing the patch, it read ambivalently[1], such
that I decided to not include the update to the man page.

[1] at the time I was reading it as "when producing a [git] commit", instead
of "the command `git commit`".

I'll send a patch fixing the docs, though with this thought, maybe we need
to fix other commands, that produce commits as well?
(git revert, others?)


>
> ---
> Kaartic

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCHv3] builtin/merge: honor commit-msg hook for merges
  2017-09-20 19:55       ` Stefan Beller
@ 2017-09-21  1:10         ` Junio C Hamano
  0 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2017-09-21  1:10 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Kaartic Sivaraam, git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> I'll send a patch fixing the docs, though with this thought, maybe we need
> to fix other commands, that produce commits as well?
> (git revert, others?)

I do not think "commands that create commits" is not a good
criteria.  "git notes" and "git stash" would (internally) create a
commit while recording a new change, but you obvously would not want
these hooks to kick in.

A command that can stop in the middle and to which running "git
commit" is how the end-user concludes the operation would be a
candidate.  "git merge X", "git cherry-pick A", and "git cherry-pick
A..B" may be good candidates.

For "rebase" and others that have the "convenience --continue"
option that make a commit before continuing, I would think that we
should treat these as invoking "git commit".  That is, when these
commands stop and you resolve the conflict in the index and in the
working tree, the next "git $cmd --continue" you type is merely a
way to let you be lazy.  You'd be typing "git commit && git $cmd
--continue" if you were to refuse the lazy convenience option and
want to spell out what you are doing explicitly, and you'd get the
same result as you'd get from just "git $cmd --continue" if you did
so.

On the other hand, "git am" is not a candidate.  You never use "git
commit" to mark that you are done, even if you refuse to use the
lazy convenience option and spell out what you are doing explicitly.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] Documentation/githooks: mention merge in commit-msg hook
  2017-09-16  6:22     ` Kaartic Sivaraam
  2017-09-20 19:55       ` Stefan Beller
@ 2017-09-21 20:29       ` Stefan Beller
  2017-09-22  1:58         ` Junio C Hamano
  1 sibling, 1 reply; 19+ messages in thread
From: Stefan Beller @ 2017-09-21 20:29 UTC (permalink / raw)
  To: kaarticsivaraam91196; +Cc: git, gitster, sbeller

The commit-msg hook is invoked by both commit and merge now.

Reported-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/githooks.txt | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 623ed1a138..f4e75b9c90 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -127,11 +127,10 @@ help message found in the commented portion of the commit template.
 commit-msg
 ~~~~~~~~~~
 
-This hook is invoked by 'git commit', and can be bypassed
-with the `--no-verify` option.  It takes a single parameter, the
-name of the file that holds the proposed commit log message.
-Exiting with a non-zero status causes the 'git commit' to
-abort.
+This hook is invoked by 'git commit' and 'git merge', and can be
+bypassed with the `--no-verify` option.  It takes a single parameter,
+the name of the file that holds the proposed commit log message.
+Exiting with a non-zero status causes the command to abort.
 
 The hook is allowed to edit the message file in place, and can be used
 to normalize the message into some project standard format. It
-- 
2.14.0.rc0.3.g6c2e499285


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] Documentation/githooks: mention merge in commit-msg hook
  2017-09-21 20:29       ` [PATCH] Documentation/githooks: mention merge in commit-msg hook Stefan Beller
@ 2017-09-22  1:58         ` Junio C Hamano
  0 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2017-09-22  1:58 UTC (permalink / raw)
  To: Stefan Beller; +Cc: kaarticsivaraam91196, git

Stefan Beller <sbeller@google.com> writes:

> The commit-msg hook is invoked by both commit and merge now.
>
> Reported-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---

Thanks for tying the loose end.  Very much appreciated.

>  Documentation/githooks.txt | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
> index 623ed1a138..f4e75b9c90 100644
> --- a/Documentation/githooks.txt
> +++ b/Documentation/githooks.txt
> @@ -127,11 +127,10 @@ help message found in the commented portion of the commit template.
>  commit-msg
>  ~~~~~~~~~~
>  
> -This hook is invoked by 'git commit', and can be bypassed
> -with the `--no-verify` option.  It takes a single parameter, the
> -name of the file that holds the proposed commit log message.
> -Exiting with a non-zero status causes the 'git commit' to
> -abort.
> +This hook is invoked by 'git commit' and 'git merge', and can be
> +bypassed with the `--no-verify` option.  It takes a single parameter,
> +the name of the file that holds the proposed commit log message.
> +Exiting with a non-zero status causes the command to abort.
>  
>  The hook is allowed to edit the message file in place, and can be used
>  to normalize the message into some project standard format. It

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-09-22  1:58 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 21:01 [PATCH] builtin/merge: honor commit-msg hook for merges Stefan Beller
2017-09-05 21:38 ` Junio C Hamano
2017-09-05 23:08   ` [PATCH] parse-options: warn developers on negated options Stefan Beller
2017-09-06  1:52     ` Junio C Hamano
2017-09-06  3:16       ` Junio C Hamano
2017-09-06 21:36         ` Stefan Beller
2017-09-06 23:41           ` Junio C Hamano
2017-09-05 23:29   ` [PATCHv2] builtin/merge: honor commit-msg hook for merges Stefan Beller
2017-09-06  1:57     ` Junio C Hamano
2017-09-06 22:11       ` Stefan Beller
2017-09-06 23:43         ` Junio C Hamano
2017-09-07 22:04   ` [PATCHv3] " Stefan Beller
2017-09-08  1:13     ` Junio C Hamano
2017-09-11 17:12       ` Stefan Beller
2017-09-16  6:22     ` Kaartic Sivaraam
2017-09-20 19:55       ` Stefan Beller
2017-09-21  1:10         ` Junio C Hamano
2017-09-21 20:29       ` [PATCH] Documentation/githooks: mention merge in commit-msg hook Stefan Beller
2017-09-22  1:58         ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).