MCPcopy Create free account
hub / github.com/git/git / prepare_to_commit

Function prepare_to_commit

builtin/merge.c:923–987  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

921
922static void write_merge_heads(struct commit_list *);
923static void prepare_to_commit(struct commit_list *remoteheads)
924{
925 struct strbuf msg = STRBUF_INIT;
926 const char *index_file = repo_get_index_file(the_repository);
927
928 if (!no_verify) {
929 int invoked_hook;
930
931 if (run_commit_hook(0 < option_edit, index_file, &invoked_hook,
932 "pre-merge-commit", NULL))
933 abort_commit(remoteheads, NULL);
934 /*
935 * Re-read the index as pre-merge-commit hook could have updated it,
936 * and write it out as a tree. We must do this before we invoke
937 * the editor and after we invoke run_status above.
938 */
939 if (invoked_hook)
940 discard_index(the_repository->index);
941 }
942 read_index_from(the_repository->index, index_file,
943 repo_get_git_dir(the_repository));
944 strbuf_addbuf(&msg, &merge_msg);
945 if (squash)
946 BUG("the control must not reach here under --squash");
947 if (0 < option_edit) {
948 strbuf_addch(&msg, '\n');
949 if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
950 wt_status_append_cut_line(&msg);
951 strbuf_commented_addf(&msg, comment_line_str, "\n");
952 }
953 strbuf_commented_addf(&msg, comment_line_str,
954 _(merge_editor_comment));
955 if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
956 strbuf_commented_addf(&msg, comment_line_str,
957 _(scissors_editor_comment));
958 else
959 strbuf_commented_addf(&msg, comment_line_str,
960 _(no_scissors_editor_comment), comment_line_str);
961 }
962 if (signoff)
963 append_signoff(&msg, ignored_log_message_bytes(msg.buf, msg.len), 0);
964 write_merge_heads(remoteheads);
965 write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len);
966 if (run_commit_hook(0 < option_edit, repo_get_index_file(the_repository),
967 NULL, "prepare-commit-msg",
968 git_path_merge_msg(the_repository), "merge", NULL))
969 abort_commit(remoteheads, NULL);
970 if (0 < option_edit) {
971 if (launch_editor(git_path_merge_msg(the_repository), NULL, NULL))
972 abort_commit(remoteheads, NULL);
973 }
974
975 if (!no_verify && run_commit_hook(0 < option_edit, repo_get_index_file(the_repository),
976 NULL, "commit-msg",
977 git_path_merge_msg(the_repository), NULL))
978 abort_commit(remoteheads, NULL);
979
980 read_merge_msg(&msg);

Callers 2

merge_trivialFunction · 0.70
finish_automergeFunction · 0.70

Calls 15

repo_get_index_fileFunction · 0.85
run_commit_hookFunction · 0.85
abort_commitFunction · 0.85
discard_indexFunction · 0.85
read_index_fromFunction · 0.85
repo_get_git_dirFunction · 0.85
strbuf_addbufFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_commented_addfFunction · 0.85
append_signoffFunction · 0.85

Tested by

no test coverage detected