| 39 | } |
| 40 | |
| 41 | static int fill_commit_message(struct repository *repo, |
| 42 | const struct object_id *old_tree, |
| 43 | const struct object_id *new_tree, |
| 44 | const char *default_message, |
| 45 | const char *action, |
| 46 | struct strbuf *out) |
| 47 | { |
| 48 | const char *path = git_path_commit_editmsg(); |
| 49 | const char *hint = |
| 50 | _("Please enter the commit message for the %s changes." |
| 51 | " Lines starting\nwith '%s' will be ignored, and an" |
| 52 | " empty message aborts the commit.\n"); |
| 53 | struct wt_status s; |
| 54 | |
| 55 | strbuf_addstr(out, default_message); |
| 56 | strbuf_addch(out, '\n'); |
| 57 | strbuf_commented_addf(out, comment_line_str, hint, action, comment_line_str); |
| 58 | write_file_buf(path, out->buf, out->len); |
| 59 | |
| 60 | wt_status_prepare(repo, &s); |
| 61 | FREE_AND_NULL(s.branch); |
| 62 | s.ahead_behind_flags = AHEAD_BEHIND_QUICK; |
| 63 | s.commit_template = 1; |
| 64 | s.colopts = 0; |
| 65 | s.display_comment_prefix = 1; |
| 66 | s.hints = 0; |
| 67 | s.use_color = 0; |
| 68 | s.whence = FROM_COMMIT; |
| 69 | s.committable = 1; |
| 70 | |
| 71 | s.fp = fopen(git_path_commit_editmsg(), "a"); |
| 72 | if (!s.fp) |
| 73 | return error_errno(_("could not open '%s'"), git_path_commit_editmsg()); |
| 74 | |
| 75 | wt_status_collect_changes_trees(&s, old_tree, new_tree); |
| 76 | wt_status_print(&s); |
| 77 | wt_status_collect_free_buffers(&s); |
| 78 | string_list_clear_func(&s.change, change_data_free); |
| 79 | |
| 80 | strbuf_reset(out); |
| 81 | if (launch_editor(path, out, NULL)) { |
| 82 | fprintf(stderr, _("Aborting commit as launching the editor failed.\n")); |
| 83 | return -1; |
| 84 | } |
| 85 | strbuf_stripspace(out, comment_line_str); |
| 86 | |
| 87 | cleanup_message(out, COMMIT_MSG_CLEANUP_ALL, 0); |
| 88 | |
| 89 | if (!out->len) { |
| 90 | fprintf(stderr, _("Aborting commit due to empty commit message.\n")); |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | enum commit_tree_flags { |
| 98 | COMMIT_TREE_EDIT_MESSAGE = (1 << 0), |
no test coverage detected