Skip to content

Commit bc40ce4

Browse files
Michael J Grubergitster
Michael J Gruber
authored andcommitted
merge: --no-verify to bypass pre-merge-commit hook
Analogous to commit, introduce a '--no-verify' option which bypasses the pre-merge-commit hook. The shorthand '-n' is taken by '--no-stat' already. [js: * reworded commit message to reflect current state of --no-stat flag and new hook name * fixed flag documentation to reflect new hook name * cleaned up trailing whitespace * squashed test changes from the original series' patch 4/4 * modified tests to follow pattern from this series' patch 1/4 * added a test case for --no-verify with non-executable hook * when testing that the merge hook did not run, make sure we actually have a merge to perform (by resetting the "side" branch to its original state). ] Improved-by: Martin Ågren <[email protected]> Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Josh Steadmon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6098817 commit bc40ce4

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

Documentation/githooks.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ the use of non-ASCII filenames.
106106
pre-merge-commit
107107
~~~~~~~~~~~~~~~~
108108

109-
This hook is invoked by linkgit:git-merge[1]. It takes no parameters, and is
109+
This hook is invoked by linkgit:git-merge[1], and can be bypassed
110+
with the `--no-verify` option. It takes no parameters, and is
110111
invoked after the merge has been carried out successfully and before
111112
obtaining the proposed commit log message to
112113
make a commit. Exiting with a non-zero status from this script

builtin/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static struct option builtin_merge_options[] = {
287287
N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
288288
OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
289289
OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
290-
OPT_BOOL(0, "no-verify", &no_verify, N_("bypass commit-msg hook")),
290+
OPT_BOOL(0, "no-verify", &no_verify, N_("bypass pre-merge-commit and commit-msg hooks")),
291291
OPT_END()
292292
};
293293

@@ -818,7 +818,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
818818
struct strbuf msg = STRBUF_INIT;
819819
const char *index_file = get_index_file();
820820

821-
if (run_commit_hook(0 < option_edit, index_file, "pre-merge-commit", NULL))
821+
if (!no_verify && run_commit_hook(0 < option_edit, index_file, "pre-merge-commit", NULL))
822822
abort_commit(remoteheads, NULL);
823823
/*
824824
* Re-read the index as pre-merge-commit hook could have updated it,

t/t7503-pre-commit-and-pre-merge-commit-hooks.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ test_expect_success '--no-verify with no hook' '
8484
test_path_is_missing actual_hooks
8585
'
8686

87+
test_expect_success '--no-verify with no hook (merge)' '
88+
test_when_finished "rm -f actual_hooks" &&
89+
git branch -f side side-orig &&
90+
git checkout side &&
91+
git merge --no-verify -m "merge master" master &&
92+
git checkout master &&
93+
test_path_is_missing actual_hooks
94+
'
95+
8796
test_expect_success 'with succeeding hook' '
8897
test_when_finished "rm -f \"$PRECOMMIT\" expected_hooks actual_hooks" &&
8998
cp "$HOOKDIR/success.sample" "$PRECOMMIT" &&
@@ -131,6 +140,16 @@ test_expect_success '--no-verify with succeeding hook' '
131140
test_path_is_missing actual_hooks
132141
'
133142

143+
test_expect_success '--no-verify with succeeding hook (merge)' '
144+
test_when_finished "rm -f \"$PREMERGE\" actual_hooks" &&
145+
cp "$HOOKDIR/success.sample" "$PREMERGE" &&
146+
git branch -f side side-orig &&
147+
git checkout side &&
148+
git merge --no-verify -m "merge master" master &&
149+
git checkout master &&
150+
test_path_is_missing actual_hooks
151+
'
152+
134153
test_expect_success 'with failing hook' '
135154
test_when_finished "rm -f \"$PRECOMMIT\" expected_hooks actual_hooks" &&
136155
cp "$HOOKDIR/fail.sample" "$PRECOMMIT" &&
@@ -160,6 +179,16 @@ test_expect_success 'with failing hook (merge)' '
160179
test_cmp expected_hooks actual_hooks
161180
'
162181

182+
test_expect_success '--no-verify with failing hook (merge)' '
183+
test_when_finished "rm -f \"$PREMERGE\" actual_hooks" &&
184+
cp "$HOOKDIR/fail.sample" "$PREMERGE" &&
185+
git branch -f side side-orig &&
186+
git checkout side &&
187+
git merge --no-verify -m "merge master" master &&
188+
git checkout master &&
189+
test_path_is_missing actual_hooks
190+
'
191+
163192
test_expect_success POSIXPERM 'with non-executable hook' '
164193
test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" &&
165194
cp "$HOOKDIR/non-exec.sample" "$PRECOMMIT" &&
@@ -188,6 +217,16 @@ test_expect_success POSIXPERM 'with non-executable hook (merge)' '
188217
test_path_is_missing actual_hooks
189218
'
190219

220+
test_expect_success POSIXPERM '--no-verify with non-executable hook (merge)' '
221+
test_when_finished "rm -f \"$PREMERGE\" actual_hooks" &&
222+
cp "$HOOKDIR/non-exec.sample" "$PREMERGE" &&
223+
git branch -f side side-orig &&
224+
git checkout side &&
225+
git merge --no-verify -m "merge master" master &&
226+
git checkout master &&
227+
test_path_is_missing actual_hooks
228+
'
229+
191230
test_expect_success 'with hook requiring GIT_PREFIX' '
192231
test_when_finished "rm -rf \"$PRECOMMIT\" expected_hooks actual_hooks success" &&
193232
cp "$HOOKDIR/require-prefix.sample" "$PRECOMMIT" &&

0 commit comments

Comments
 (0)