| 760 | } |
| 761 | |
| 762 | static int prepare_to_commit(const char *index_file, const char *prefix, |
| 763 | struct commit *current_head, |
| 764 | struct wt_status *s, |
| 765 | struct strbuf *author_ident) |
| 766 | { |
| 767 | struct stat statbuf; |
| 768 | struct strbuf committer_ident = STRBUF_INIT; |
| 769 | int committable; |
| 770 | struct strbuf sb = STRBUF_INIT; |
| 771 | const char *hook_arg1 = NULL; |
| 772 | const char *hook_arg2 = NULL; |
| 773 | int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE); |
| 774 | int old_display_comment_prefix; |
| 775 | int invoked_hook; |
| 776 | |
| 777 | /* This checks and barfs if author is badly specified */ |
| 778 | determine_author_info(author_ident); |
| 779 | |
| 780 | if (!no_verify && run_commit_hook(use_editor, index_file, &invoked_hook, |
| 781 | "pre-commit", NULL)) |
| 782 | return 0; |
| 783 | |
| 784 | if (squash_message) { |
| 785 | /* |
| 786 | * Insert the proper subject line before other commit |
| 787 | * message options add their content. |
| 788 | */ |
| 789 | if (use_message && !strcmp(use_message, squash_message)) |
| 790 | strbuf_addstr(&sb, "squash! "); |
| 791 | else { |
| 792 | struct pretty_print_context ctx = {0}; |
| 793 | struct commit *c; |
| 794 | c = lookup_commit_reference_by_name(squash_message); |
| 795 | if (!c) |
| 796 | die(_("could not lookup commit '%s'"), squash_message); |
| 797 | ctx.output_encoding = get_commit_output_encoding(); |
| 798 | repo_format_commit_message(the_repository, c, |
| 799 | "squash! %s\n\n", &sb, |
| 800 | &ctx); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | if (have_option_m && !fixup_message) { |
| 805 | strbuf_addbuf(&sb, &message); |
| 806 | hook_arg1 = "message"; |
| 807 | } else if (logfile && !strcmp(logfile, "-")) { |
| 808 | if (isatty(0)) |
| 809 | fprintf(stderr, _("(reading log message from standard input)\n")); |
| 810 | if (strbuf_read(&sb, 0, 0) < 0) |
| 811 | die_errno(_("could not read log from standard input")); |
| 812 | hook_arg1 = "message"; |
| 813 | } else if (logfile) { |
| 814 | if (strbuf_read_file(&sb, logfile, 0) < 0) |
| 815 | die_errno(_("could not read log file '%s'"), |
| 816 | logfile); |
| 817 | hook_arg1 = "message"; |
| 818 | } else if (use_message) { |
| 819 | const char *buffer; |
no test coverage detected