Skip to content

Commit 678989c

Browse files
committed
Merge branch 'ow/rebase-verify-insn-fmt-before-initializing-state' into seen
"git rebase -i" with bogus rebase.instructionFormat configuration failed to produce the todo file after recording the state files, leading to confused "git status"; this has been corrected. Comments? * ow/rebase-verify-insn-fmt-before-initializing-state: rebase: write script before initializing state
2 parents 8cdc48e + ade14bf commit 678989c

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

builtin/rebase.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,6 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
293293
&revisions, &shortrevisions))
294294
goto cleanup;
295295

296-
if (init_basic_state(&replay,
297-
opts->head_name ? opts->head_name : "detached HEAD",
298-
opts->onto, &opts->orig_head->object.oid))
299-
goto cleanup;
300-
301-
if (!opts->upstream && opts->squash_onto)
302-
write_file(path_squash_onto(), "%s\n",
303-
oid_to_hex(opts->squash_onto));
304-
305296
strvec_pushl(&make_script_args, "", revisions, NULL);
306297
if (opts->restrict_revision)
307298
strvec_pushf(&make_script_args, "^%s",
@@ -310,21 +301,30 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
310301
ret = sequencer_make_script(the_repository, &todo_list.buf,
311302
make_script_args.nr, make_script_args.v,
312303
flags);
313-
314-
if (ret)
304+
if (ret) {
315305
error(_("could not generate todo list"));
316-
else {
317-
discard_index(the_repository->index);
318-
if (todo_list_parse_insn_buffer(the_repository, &replay,
319-
todo_list.buf.buf, &todo_list))
320-
BUG("unusable todo list");
321-
322-
ret = complete_action(the_repository, &replay, flags,
323-
shortrevisions, opts->onto_name, opts->onto,
324-
&opts->orig_head->object.oid, &opts->exec,
325-
opts->autosquash, opts->update_refs, &todo_list);
306+
goto cleanup;
326307
}
327308

309+
if (init_basic_state(&replay,
310+
opts->head_name ? opts->head_name : "detached HEAD",
311+
opts->onto, &opts->orig_head->object.oid))
312+
goto cleanup;
313+
314+
if (!opts->upstream && opts->squash_onto)
315+
write_file(path_squash_onto(), "%s\n",
316+
oid_to_hex(opts->squash_onto));
317+
318+
discard_index(the_repository->index);
319+
if (todo_list_parse_insn_buffer(the_repository, &replay,
320+
todo_list.buf.buf, &todo_list))
321+
BUG("unusable todo list");
322+
323+
ret = complete_action(the_repository, &replay, flags,
324+
shortrevisions, opts->onto_name, opts->onto,
325+
&opts->orig_head->object.oid, &opts->exec,
326+
opts->autosquash, opts->update_refs, &todo_list);
327+
328328
cleanup:
329329
replay_opts_release(&replay);
330330
free(revisions);

t/t3415-rebase-autosquash.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,16 @@ test_expect_success 'autosquash with empty custom instructionFormat' '
394394
)
395395
'
396396

397+
test_expect_success 'autosquash with invalid custom instructionFormat' '
398+
git reset --hard base &&
399+
test_commit invalid-instructionFormat-test &&
400+
(
401+
test_must_fail git -c rebase.instructionFormat=blah \
402+
rebase --autosquash --force-rebase -i HEAD^ &&
403+
test_path_is_missing .git/rebase-merge
404+
)
405+
'
406+
397407
set_backup_editor () {
398408
write_script backup-editor.sh <<-\EOF
399409
cp "$1" .git/backup-"$(basename "$1")"

0 commit comments

Comments
 (0)