Skip to content

Commit fc4a673

Browse files
phillipwoodgitster
authored andcommitted
sequencer: always discard index after checkout
As the checkout runs in a separate process our index will be out of date so it should be discarded. The existing callers are not doing this consistently so do it here to avoid the callers having to worry about it. This fixes some test failures that happen if do_interactive_rebase() is called without forking rebase--interactive which we will implement shortly. Running git rebase -i master topic starting on master created empty todo lists because all the commits in topic were marked as cherry-picks. After topic was checked out in prepare_branch_to_be_rebased() the working tree contained the contents from topic but the index contained master and the cache entries were still valid. This meant that diff_populate_filespec() which loads the blobs when calculating patch-id's ended up reading the contents for master from the working tree which actually contained topic. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 464c824 commit fc4a673

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

builtin/rebase--interactive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
171171
struct argv_array make_script_args = ARGV_ARRAY_INIT;
172172
struct todo_list todo_list = TODO_LIST_INIT;
173173

174-
if (prepare_branch_to_be_rebased(opts, switch_to))
174+
if (prepare_branch_to_be_rebased(the_repository, opts, switch_to))
175175
return -1;
176176

177177
if (get_revision_ranges(upstream, onto, &head_hash,

sequencer.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,10 +3418,11 @@ static const char *reflog_message(struct replay_opts *opts,
34183418
return buf.buf;
34193419
}
34203420

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)
34233423
{
34243424
struct child_process cmd = CHILD_PROCESS_INIT;
3425+
int ret;
34253426

34263427
cmd.git_cmd = 1;
34273428

@@ -3430,25 +3431,31 @@ static int run_git_checkout(struct replay_opts *opts, const char *commit,
34303431
argv_array_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);
34313432

34323433
if (opts->verbose)
3433-
return run_command(&cmd);
3434+
ret = run_command(&cmd);
34343435
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;
34363442
}
34373443

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)
34393446
{
34403447
const char *action;
34413448

34423449
if (commit && *commit) {
34433450
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))
34453452
return error(_("could not checkout %s"), commit);
34463453
}
34473454

34483455
return 0;
34493456
}
34503457

3451-
static int checkout_onto(struct replay_opts *opts,
3458+
static int checkout_onto(struct repository *r, struct replay_opts *opts,
34523459
const char *onto_name, const char *onto,
34533460
const char *orig_head)
34543461
{
@@ -3458,7 +3465,7 @@ static int checkout_onto(struct replay_opts *opts,
34583465
if (get_oid(orig_head, &oid))
34593466
return error(_("%s: not a valid OID"), orig_head);
34603467

3461-
if (run_git_checkout(opts, onto, action)) {
3468+
if (run_git_checkout(r, opts, onto, action)) {
34623469
apply_autostash(opts);
34633470
sequencer_remove_state(opts);
34643471
return error(_("could not detach HEAD"));
@@ -4786,7 +4793,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
47864793
if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) ||
47874794
todo_list_check(todo_list, &new_todo)) {
47884795
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);
47904797
todo_list_release(&new_todo);
47914798

47924799
return -1;
@@ -4805,7 +4812,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
48054812

48064813
todo_list_release(&new_todo);
48074814

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))
48094816
return -1;
48104817

48114818
if (require_clean_work_tree(r, "rebase", "", 1, 1))

sequencer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ void commit_post_rewrite(struct repository *r,
175175
const struct commit *current_head,
176176
const struct object_id *new_head);
177177

178-
int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit);
178+
int prepare_branch_to_be_rebased(struct repository *r, struct replay_opts *opts,
179+
const char *commit);
179180

180181
#define SUMMARY_INITIAL_COMMIT (1 << 0)
181182
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)

0 commit comments

Comments
 (0)