Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "commit.h" |
| 3 | #include "rebase-interactive.h" |
| 4 | #include "sequencer.h" |
| 5 | #include "strbuf.h" |
| 6 | |
Alban Gruin | a9f5476 | 2018-08-10 18:51:35 +0200 | [diff] [blame] | 7 | void append_todo_help(unsigned edit_todo, unsigned keep_empty, |
| 8 | struct strbuf *buf) |
Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 9 | { |
Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 10 | const char *msg = _("\nCommands:\n" |
| 11 | "p, pick <commit> = use commit\n" |
| 12 | "r, reword <commit> = use commit, but edit the commit message\n" |
| 13 | "e, edit <commit> = use commit, but stop for amending\n" |
| 14 | "s, squash <commit> = use commit, but meld into previous commit\n" |
| 15 | "f, fixup <commit> = like \"squash\", but discard this commit's log message\n" |
| 16 | "x, exec <command> = run command (the rest of the line) using shell\n" |
Johannes Schindelin | 71f8246 | 2018-10-12 06:14:26 -0700 | [diff] [blame] | 17 | "b, break = stop here (continue rebase later with 'git rebase --continue')\n" |
Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 18 | "d, drop <commit> = remove commit\n" |
| 19 | "l, label <label> = label current HEAD with a name\n" |
| 20 | "t, reset <label> = reset HEAD to a label\n" |
| 21 | "m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]\n" |
| 22 | ". create a merge commit using the original merge commit's\n" |
| 23 | ". message (or the oneline, if no original merge commit was\n" |
| 24 | ". specified). Use -c <commit> to reword the commit message.\n" |
| 25 | "\n" |
| 26 | "These lines can be re-ordered; they are executed from top to bottom.\n"); |
| 27 | |
Alban Gruin | a9f5476 | 2018-08-10 18:51:35 +0200 | [diff] [blame] | 28 | strbuf_add_commented_lines(buf, msg, strlen(msg)); |
Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 29 | |
| 30 | if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR) |
| 31 | msg = _("\nDo not remove any line. Use 'drop' " |
| 32 | "explicitly to remove a commit.\n"); |
| 33 | else |
| 34 | msg = _("\nIf you remove a line here " |
| 35 | "THAT COMMIT WILL BE LOST.\n"); |
| 36 | |
Alban Gruin | a9f5476 | 2018-08-10 18:51:35 +0200 | [diff] [blame] | 37 | strbuf_add_commented_lines(buf, msg, strlen(msg)); |
Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 38 | |
| 39 | if (edit_todo) |
| 40 | msg = _("\nYou are editing the todo file " |
| 41 | "of an ongoing interactive rebase.\n" |
| 42 | "To continue rebase after editing, run:\n" |
| 43 | " git rebase --continue\n\n"); |
| 44 | else |
| 45 | msg = _("\nHowever, if you remove everything, " |
| 46 | "the rebase will be aborted.\n\n"); |
| 47 | |
Alban Gruin | a9f5476 | 2018-08-10 18:51:35 +0200 | [diff] [blame] | 48 | strbuf_add_commented_lines(buf, msg, strlen(msg)); |
Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 49 | |
| 50 | if (!keep_empty) { |
| 51 | msg = _("Note that empty commits are commented out"); |
Alban Gruin | a9f5476 | 2018-08-10 18:51:35 +0200 | [diff] [blame] | 52 | strbuf_add_commented_lines(buf, msg, strlen(msg)); |
Alban Gruin | 145e05a | 2018-08-10 18:51:29 +0200 | [diff] [blame] | 53 | } |
Alban Gruin | a9f5476 | 2018-08-10 18:51:35 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Alban Gruin | 64a43cb | 2018-08-10 18:51:31 +0200 | [diff] [blame] | 56 | int edit_todo_list(unsigned flags) |
| 57 | { |
| 58 | struct strbuf buf = STRBUF_INIT; |
| 59 | const char *todo_file = rebase_path_todo(); |
| 60 | |
| 61 | if (strbuf_read_file(&buf, todo_file, 0) < 0) |
| 62 | return error_errno(_("could not read '%s'."), todo_file); |
| 63 | |
| 64 | strbuf_stripspace(&buf, 1); |
| 65 | if (write_message(buf.buf, buf.len, todo_file, 0)) { |
| 66 | strbuf_release(&buf); |
| 67 | return -1; |
| 68 | } |
| 69 | |
| 70 | strbuf_release(&buf); |
| 71 | |
| 72 | transform_todos(flags | TODO_LIST_SHORTEN_IDS); |
Alban Gruin | a9f5476 | 2018-08-10 18:51:35 +0200 | [diff] [blame] | 73 | |
| 74 | if (strbuf_read_file(&buf, todo_file, 0) < 0) |
| 75 | return error_errno(_("could not read '%s'."), todo_file); |
| 76 | |
| 77 | append_todo_help(1, 0, &buf); |
| 78 | if (write_message(buf.buf, buf.len, todo_file, 0)) { |
| 79 | strbuf_release(&buf); |
| 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | strbuf_release(&buf); |
Alban Gruin | 64a43cb | 2018-08-10 18:51:31 +0200 | [diff] [blame] | 84 | |
| 85 | if (launch_sequence_editor(todo_file, NULL, NULL)) |
| 86 | return -1; |
| 87 | |
| 88 | transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS)); |
| 89 | |
| 90 | return 0; |
| 91 | } |