builtin/merge: honor commit-msg hook for merges
Subsystems (2)
PATCH 1/1 builtin/merge: honor commit-msg hook for merges
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.
--- builtin/merge.c | 8 ++++++++ t/t7504-commit-msg-hook.sh | 45 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 4 deletions(-)
builtin/merge.c +8 -0
@@ -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)
t/t7504-commit-msg-hook.sh +41 -4
74 lines not on this page · raw message
Signature · 1 line
2.14.0.rc0.3.g6c2e499285
Quoted 6 lines · 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.
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 ;-).
Quoted 1 line
This change is motivated by Gerrits commit-msg hook to install a change-id
s/Gerrits/Gerrit's/ perhaps?
Quoted 1 line
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".
Quoted 3 lines
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.
Quoted 19 lines
Signed-off-by Stefan Beller <[email protected]>--- builtin/merge.c | 8 ++++++++ t/t7504-commit-msg-hook.sh | 45 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 4 deletions(-)builtin/merge.c +1
-0@@ -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 },
builtin/merge.c static struct option builtin_merge_options[] = { · line 240
Quoted 4 lines
builtin/merge.c +1
-0@@ -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.
PATCH 1/1 parse-options: warn developers on negated options
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").
---
#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(-)
Makefile +2 -1
@@ -433,7 +433,8 @@ DEVELOPER_CFLAGS = -Werror \ -Wpointer-arith \ -Wstrict-prototypes \ -Wunused \ - -Wvla + -Wvla \ + -DDEVELOPER LDFLAGS = ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS)
parse-options.c +6 -0
@@ -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 );
parse-options.h +5 -2
@@ -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, \
Signature · 1 line
2.14.0.rc0.3.g6c2e499285
Re: [PATCH] parse-options: warn developers on negated options
Quoted 2 lines · Stefan Beller
This patch disallows all no- options, but we could be more open and allow --no-options that have the
NO_NEGbit 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.
Re: [PATCH] parse-options: warn developers on negated options
Quoted 5 lines · Junio C Hamano
Quoted 2 lines · Stefan Beller
This patch disallows all no- options, but we could be more open and allow --no-options that have the
NO_NEGbit set.
Quoted 8 lines
"--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.
Quoted 9 lines
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.
Re: [PATCH] parse-options: warn developers on negated options
Quoted 41 lines · Junio C Hamano
Quoted 5 lines · Junio C Hamano
Quoted 2 lines · Stefan Beller
This patch disallows all no- options, but we could be more open and allow --no-options that have the
NO_NEGbit set.Quoted 8 lines
"--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" inbuiltin/merge.cand existing one incommit.cOK long time ago. A quick check to see how your version ofgit merge --verify git merge --no-verifybehaves 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.
Quoted 9 lines
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.
Quoted 5 lines
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
Quoted 2 lines
Thanks.
Re: [PATCH] parse-options: warn developers on negated options
Quoted 31 lines · Stefan Beller
Quoted 25 lines
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" inbuiltin/merge.cand existing one incommit.cOK long time ago. A quick check to see how your version ofgit merge --verify git merge --no-verifybehaves 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.
Quoted 9 lines
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.Quoted 5 lines
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.
Quoted 3 lines
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.
PATCH v2 1/1 builtin/merge: honor commit-msg hook for merges
In reply to Junio C HamanoSimilar 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.
---
addressed all but one issues.
Quoted 4 lines · Junio
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(-)
builtin/merge.c +8 -0
@@ -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)
t/t7504-commit-msg-hook.sh +41 -4
74 lines not on this page · raw message
Signature · 1 line
2.14.0.rc0.3.g6c2e499285
Quoted 19 lines · Stefan Beller
Quoted 4 lines · Junio
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 tocmd_commitwill 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")),
...
Quoted 12 lines
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.
Quoted 29 lines · Junio C Hamano
Quoted 27 lines · Stefan Beller
Quoted 4 lines · Junio
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 tocmd_commitwill 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);
Quoted 7 lines
Quoted 4 lines
/* 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....
Quoted 4 lines
I also thought that we were hunting calls of
cmd_foo()from outside thegit.ccommand 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?)
Quoted 5 lines
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?
Quoted 7 lines · Stefan Beller
Quoted 3 lines
I also thought that we were hunting calls of
cmd_foo()from outside thegit.ccommand 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/[email protected]/
gives a good explanation why it is not a good state.
PATCH v3 1/1 builtin/merge: honor commit-msg hook for merges
In reply to Junio C HamanoSimilar 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.
---
Quoted 4 lines
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(-)
builtin/merge.c +8 -0
@@ -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)
t/t7504-commit-msg-hook.sh +60 -4
93 lines not on this page · raw message
Signature · 1 line
2.14.0.rc0.3.g6c2e499285
Quoted 5 lines · Stefan Beller
.... 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.
builtin/merge.c static struct option builtin_merge_options[] = { · line 242
Quoted 11 lines
builtin/merge.c +2
-0+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.
t/t7504-commit-msg-hook.sh test_expect_success '--no-verify with failing hook (editor)' ' · line 165
Quoted 7 lines
t/t7504-commit-msg-hook.sh +7
-0+test_expect_success 'merge fails with failing hook' ' + ... +' + +test_expect_success 'merge bypasses failing hook with --no-verify' ' + ... +'
Both look sensible.
Quoted 8 lines
t/t7504-commit-msg-hook.sh +8
-0+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^ &&
t/t7504-commit-msg-hook.sh test_expect_success "hook doesn't edit commit message (editor)" ' · line 276
Quoted 10 lines
t/t7504-commit-msg-hook.sh +9
-0+ 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.
Quoted 10 lines · Junio C Hamano
Quoted 5 lines · Stefan Beller
.... 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.
Quoted 9 lines
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.
Quoted 6 lines
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.
Quoted 4 lines
Quoted 4 lines
+static int
verify_msg= 1;
Quoted 16 lines
builtin/merge.c static struct option builtin_merge_options[] = { · line 242
Quoted 9 lines
static struct strategy all_strategy[] = {
{ "recursive",DEFAULT_TWOHEAD|NO_TRIVIAL},builtin/merge.c +1
-0@@ -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.
Quoted 19 lines
Quoted 8 lines
t/t7504-commit-msg-hook.sh +8
-0+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^ &&t/t7504-commit-msg-hook.sh test_expect_success "hook doesn't edit commit message (editor)" ' · line 276
Quoted 10 lines
t/t7504-commit-msg-hook.sh +9
-0+ 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 '
Quoted 2 lines
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.
Quoted 3 lines
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.
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
Quoted 9 lines · Kaartic Sivaraam
Seems '
Documentation/githooks.txt' needs an update related to this change. Previously itsaid(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?)
Quoted 3 lines
---
Kaartic
Quoted 3 lines · Stefan Beller
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.
PATCH 1/1 Documentation/githooks: mention merge in commit-msg hook
In reply to Kaartic SivaraamThe commit-msg hook is invoked by both commit and merge now.
--- Documentation/githooks.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Documentation/githooks.txt +4 -5
@@ -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
Signature · 1 line
2.14.0.rc0.3.g6c2e499285
Re: [PATCH] Documentation/githooks: mention merge in commit-msg hook
Quoted 5 lines · Stefan Beller
The commit-msg hook is invoked by both commit and merge now.
Reported-by Kaartic Sivaraam <[email protected]>Signed-off-by Stefan Beller <[email protected]>---
Thanks for tying the loose end. Very much appreciated.
Quoted 23 lines
Documentation/githooks.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)Documentation/githooks.txt +4
-5@@ -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