"\n"
" git rebase --continue\n");
+#define ALLOW_EMPTY (1<<0)
+#define EDIT_MSG (1<<1)
+#define AMEND_MSG (1<<2)
+#define CLEANUP_MSG (1<<3)
+#define VERIFY_MSG (1<<4)
+
/*
* If we are cherry-pick, and if the merge did not result in
* hand-editing, we will hit this commit and inherit the original
* author metadata.
*/
static int run_git_commit(const char *defmsg, struct replay_opts *opts,
- int allow_empty, int edit, int amend,
- int cleanup_commit_message)
+ unsigned int flags)
{
struct child_process cmd = CHILD_PROCESS_INIT;
const char *value;
cmd.git_cmd = 1;
if (is_rebase_i(opts)) {
- if (!edit) {
+ if (!(flags & EDIT_MSG)) {
cmd.stdout_to_stderr = 1;
cmd.err = -1;
}
}
argv_array_push(&cmd.args, "commit");
- argv_array_push(&cmd.args, "-n");
- if (amend)
+ if (!(flags & VERIFY_MSG))
+ argv_array_push(&cmd.args, "-n");
+ if ((flags & AMEND_MSG))
argv_array_push(&cmd.args, "--amend");
if (opts->gpg_sign)
argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
argv_array_push(&cmd.args, "-s");
if (defmsg)
argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
- if (cleanup_commit_message)
+ if ((flags & CLEANUP_MSG))
argv_array_push(&cmd.args, "--cleanup=strip");
- if (edit)
+ if ((flags & EDIT_MSG))
argv_array_push(&cmd.args, "-e");
- else if (!cleanup_commit_message &&
+ else if (!(flags & CLEANUP_MSG) &&
!opts->signoff && !opts->record_origin &&
git_config_get_value("commit.cleanup", &value))
argv_array_push(&cmd.args, "--cleanup=verbatim");
- if (allow_empty)
+ if ((flags & ALLOW_EMPTY))
argv_array_push(&cmd.args, "--allow-empty");
if (opts->allow_empty_message)
static int do_pick_commit(enum todo_command command, struct commit *commit,
struct replay_opts *opts, int final_fixup)
{
- int edit = opts->edit, cleanup_commit_message = 0;
- const char *msg_file = edit ? NULL : git_path_merge_msg();
+ unsigned int flags = opts->edit ? EDIT_MSG : 0;
+ const char *msg_file = opts->edit ? NULL : git_path_merge_msg();
unsigned char head[20];
struct commit *base, *next, *parent;
const char *base_label, *next_label;
struct commit_message msg = { NULL, NULL, NULL, NULL };
struct strbuf msgbuf = STRBUF_INIT;
- int res, unborn = 0, amend = 0, allow = 0;
+ int res, unborn = 0, allow;
if (opts->no_commit) {
/*
opts);
if (res || command != TODO_REWORD)
goto leave;
- edit = amend = 1;
+ flags |= EDIT_MSG | AMEND_MSG;
+ if (command == TODO_REWORD)
+ flags |= VERIFY_MSG;
msg_file = NULL;
goto fast_forward_edit;
}
}
if (command == TODO_REWORD)
- edit = 1;
+ flags |= EDIT_MSG | VERIFY_MSG;
else if (is_fixup(command)) {
if (update_squash_messages(command, commit, opts))
return -1;
- amend = 1;
+ flags |= AMEND_MSG;
if (!final_fixup)
msg_file = rebase_path_squash_msg();
else if (file_exists(rebase_path_fixup_msg())) {
- cleanup_commit_message = 1;
+ flags |= CLEANUP_MSG;
msg_file = rebase_path_fixup_msg();
} else {
const char *dest = git_path_squash_msg();
rebase_path_squash_msg(), dest);
unlink(git_path_merge_msg());
msg_file = dest;
- edit = 1;
+ flags |= EDIT_MSG;
}
}
if (allow < 0) {
res = allow;
goto leave;
- }
+ } else if (allow)
+ flags |= ALLOW_EMPTY;
if (!opts->no_commit)
fast_forward_edit:
- res = run_git_commit(msg_file, opts, allow, edit, amend,
- cleanup_commit_message);
+ res = run_git_commit(msg_file, opts, flags);
if (!res && final_fixup) {
unlink(rebase_path_fixup_msg());
struct todo_item *items;
int nr, alloc, current;
int done_nr, total_nr;
+ struct stat_data stat;
};
#define TODO_LIST_INIT { STRBUF_INIT }
static int read_populate_todo(struct todo_list *todo_list,
struct replay_opts *opts)
{
+ struct stat st;
const char *todo_file = get_todo_path(opts);
int fd, res;
}
close(fd);
+ res = stat(todo_file, &st);
+ if (res)
+ return error(_("could not stat '%s'"), todo_file);
+ fill_stat_data(&todo_list->stat, &st);
+
res = parse_insn_buffer(todo_list->buf.buf, todo_list);
if (res) {
if (is_rebase_i(opts))
if (item->command == TODO_EDIT) {
struct commit *commit = item->commit;
if (!res)
- warning(_("stopped at %s... %.*s"),
+ fprintf(stderr,
+ _("Stopped at %s... %.*s\n"),
short_commit_name(commit),
item->arg_len, item->arg);
return error_with_patch(commit,
} else if (item->command == TODO_EXEC) {
char *end_of_arg = (char *)(item->arg + item->arg_len);
int saved = *end_of_arg;
+ struct stat st;
*end_of_arg = '\0';
res = do_exec(item->arg);
*end_of_arg = saved;
+
+ /* Reread the todo file if it has changed. */
+ if (res)
+ ; /* fall through */
+ else if (stat(get_todo_path(opts), &st))
+ res = error_errno(_("could not stat '%s'"),
+ get_todo_path(opts));
+ else if (match_stat_data(&todo_list->stat, &st)) {
+ todo_list_release(todo_list);
+ if (read_populate_todo(todo_list, opts))
+ res = -1; /* message was printed */
+ /* `current` will be incremented below */
+ todo_list->current = -1;
+ }
} else if (!is_noop(item->command))
return error(_("unknown command %d"), item->command);
static int commit_staged_changes(struct replay_opts *opts)
{
- int amend = 0;
+ unsigned int flags = ALLOW_EMPTY | EDIT_MSG;
if (has_unstaged_changes(1))
return error(_("cannot rebase: You have unstaged changes."));
"--continue' again."));
strbuf_release(&rev);
- amend = 1;
+ flags |= AMEND_MSG;
}
- if (run_git_commit(rebase_path_message(), opts, 1, 1, amend, 0))
+ if (run_git_commit(rebase_path_message(), opts, flags))
return error(_("could not commit staged changes."));
unlink(rebase_path_amend());
return 0;