* Check if the user dropped some commits by mistake * Behaviour determined by rebase.missingCommitsCheck. * Check if there is an unrecognized command or a * bad SHA-1 in a command. */
| 174 | * bad SHA-1 in a command. |
| 175 | */ |
| 176 | int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo) |
| 177 | { |
| 178 | enum missing_commit_check_level check_level = get_missing_commit_check_level(); |
| 179 | struct strbuf missing = STRBUF_INIT; |
| 180 | int res = 0, i; |
| 181 | struct commit_seen commit_seen; |
| 182 | |
| 183 | init_commit_seen(&commit_seen); |
| 184 | |
| 185 | if (check_level == MISSING_COMMIT_CHECK_IGNORE) |
| 186 | goto leave_check; |
| 187 | |
| 188 | /* Mark the commits in git-rebase-todo as seen */ |
| 189 | for (i = 0; i < new_todo->nr; i++) { |
| 190 | struct commit *commit = new_todo->items[i].commit; |
| 191 | if (commit) |
| 192 | *commit_seen_at(&commit_seen, commit) = 1; |
| 193 | } |
| 194 | |
| 195 | /* Find commits in git-rebase-todo.backup yet unseen */ |
| 196 | for (i = old_todo->nr - 1; i >= 0; i--) { |
| 197 | struct todo_item *item = old_todo->items + i; |
| 198 | struct commit *commit = item->commit; |
| 199 | if (commit && !*commit_seen_at(&commit_seen, commit)) { |
| 200 | strbuf_addf(&missing, " - %s %.*s\n", |
| 201 | repo_find_unique_abbrev(the_repository, &commit->object.oid, DEFAULT_ABBREV), |
| 202 | item->arg_len, |
| 203 | todo_item_get_arg(old_todo, item)); |
| 204 | *commit_seen_at(&commit_seen, commit) = 1; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /* Warn about missing commits */ |
| 209 | if (!missing.len) |
| 210 | goto leave_check; |
| 211 | |
| 212 | if (check_level == MISSING_COMMIT_CHECK_ERROR) |
| 213 | res = 1; |
| 214 | |
| 215 | fprintf(stderr, |
| 216 | _("Warning: some commits may have been dropped accidentally.\n" |
| 217 | "Dropped commits (newer to older):\n")); |
| 218 | |
| 219 | /* Make the list user-friendly and display */ |
| 220 | fputs(missing.buf, stderr); |
| 221 | strbuf_release(&missing); |
| 222 | |
| 223 | fprintf(stderr, _("To avoid this message, use \"drop\" to " |
| 224 | "explicitly remove a commit.\n\n" |
| 225 | "Use 'git config rebase.missingCommitsCheck' to change " |
| 226 | "the level of warnings.\n" |
| 227 | "The possible behaviours are: ignore, warn, error.\n\n")); |
| 228 | |
| 229 | fprintf(stderr, _(edit_todo_list_advice)); |
| 230 | |
| 231 | leave_check: |
| 232 | clear_commit_seen(&commit_seen); |
| 233 | return res; |
no test coverage detected