Merge branch 'sb/merge-commit-msg-hook'
As "git commit" to conclude a conflicted "git merge" honors the commit-msg hook, "git merge" that recoreds a merge commit that cleanly auto-merges should, but it didn't. * sb/merge-commit-msg-hook: builtin/merge: honor commit-msg hook for merges
This commit is contained in:
commit
0543de438f
@ -73,6 +73,7 @@ static int show_progress = -1;
|
|||||||
static int default_to_upstream = 1;
|
static int default_to_upstream = 1;
|
||||||
static int signoff;
|
static int signoff;
|
||||||
static const char *sign_commit;
|
static const char *sign_commit;
|
||||||
|
static int verify_msg = 1;
|
||||||
|
|
||||||
static struct strategy all_strategy[] = {
|
static struct strategy all_strategy[] = {
|
||||||
{ "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
|
{ "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) "" },
|
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, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
|
||||||
OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
|
OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")),
|
||||||
|
OPT_BOOL(0, "verify", &verify_msg, N_("verify commit-msg hook")),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -780,6 +782,12 @@ static void prepare_to_commit(struct commit_list *remoteheads)
|
|||||||
if (launch_editor(git_path_merge_msg(), NULL, NULL))
|
if (launch_editor(git_path_merge_msg(), NULL, NULL))
|
||||||
abort_commit(remoteheads, 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);
|
read_merge_msg(&msg);
|
||||||
strbuf_stripspace(&msg, 0 < option_edit);
|
strbuf_stripspace(&msg, 0 < option_edit);
|
||||||
if (!msg.len)
|
if (!msg.len)
|
||||||
|
@ -101,6 +101,10 @@ cat > "$HOOK" <<EOF
|
|||||||
exit 1
|
exit 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
commit_msg_is () {
|
||||||
|
test "$(git log --pretty=format:%s%b -1)" = "$1"
|
||||||
|
}
|
||||||
|
|
||||||
test_expect_success 'with failing hook' '
|
test_expect_success 'with failing hook' '
|
||||||
|
|
||||||
echo "another" >> file &&
|
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"
|
chmod -x "$HOOK"
|
||||||
test_expect_success POSIXPERM 'with non-executable hook' '
|
test_expect_success POSIXPERM 'with non-executable hook' '
|
||||||
|
|
||||||
@ -178,10 +208,6 @@ exit 0
|
|||||||
EOF
|
EOF
|
||||||
chmod +x "$HOOK"
|
chmod +x "$HOOK"
|
||||||
|
|
||||||
commit_msg_is () {
|
|
||||||
test "$(git log --pretty=format:%s%b -1)" = "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_expect_success 'hook edits commit message' '
|
test_expect_success 'hook edits commit message' '
|
||||||
|
|
||||||
echo "additional" >> file &&
|
echo "additional" >> file &&
|
||||||
@ -217,7 +243,36 @@ test_expect_success "hook doesn't edit commit message (editor)" '
|
|||||||
echo "more plus" > FAKE_MSG &&
|
echo "more plus" > FAKE_MSG &&
|
||||||
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
|
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
|
||||||
commit_msg_is "more plus"
|
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`
|
# 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
|
test_done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user