3418
return buf.buf;
3419
}
3420
3421
-static int run_git_checkout(struct replay_opts *opts, const char *commit,
3422
- const char *action)
3421
+static int run_git_checkout(struct repository *r, struct replay_opts *opts,
3422
+ const char *commit, const char *action)
3423
{
3424
struct child_process cmd = CHILD_PROCESS_INIT;
3425
+ int ret;
3426
3427
cmd.git_cmd = 1;
3428
3431
argv_array_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);
3432
3433
if (opts->verbose)
3433
- return run_command(&cmd);
3434
+ ret = run_command(&cmd);
3435
else
3435
- return run_command_silent_on_success(&cmd);
3436
+ ret = run_command_silent_on_success(&cmd);
3437
+
3438
+ if (!ret)
3439
+ discard_index(r->index);
3440
+
3441
+ return ret;
3442
}
3443
3438
-int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit)
3444
+int prepare_branch_to_be_rebased(struct repository *r, struct replay_opts *opts,
3445
+ const char *commit)
3446
{
3447
const char *action;
3448
3449
if (commit && *commit) {
3450
action = reflog_message(opts, "start", "checkout %s", commit);
3444
- if (run_git_checkout(opts, commit, action))
3451
+ if (run_git_checkout(r, opts, commit, action))
3452
return error(_("could not checkout %s"), commit);
3453
}
3454
3455
return 0;
3456
}
3457
3451
-static int checkout_onto(struct replay_opts *opts,
3458
+static int checkout_onto(struct repository *r, struct replay_opts *opts,
3459
const char *onto_name, const char *onto,
3460
const char *orig_head)
3461
{
3465
if (get_oid(orig_head, &oid))
3466
return error(_("%s: not a valid OID"), orig_head);
3467
3461
- if (run_git_checkout(opts, onto, action)) {
3468
+ if (run_git_checkout(r, opts, onto, action)) {
3469
apply_autostash(opts);
3470
sequencer_remove_state(opts);
3471
return error(_("could not detach HEAD"));
4793
if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) ||
4794
todo_list_check(todo_list, &new_todo)) {
4795
fprintf(stderr, _(edit_todo_list_advice));
4789
- checkout_onto(opts, onto_name, onto, orig_head);
4796
+ checkout_onto(r, opts, onto_name, onto, orig_head);
4797
todo_list_release(&new_todo);
4798
4799
return -1;
4812
4813
todo_list_release(&new_todo);
4814
4808
- if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head))
4815
+ if (checkout_onto(r, opts, onto_name, oid_to_hex(&oid), orig_head))
4816
return -1;
4817
4818
if (require_clean_work_tree(r, "rebase", "", 1, 1))