Skip to content

Commit 4b3517e

Browse files
committed
Merge branch 'js/rebase-in-c-5.5-work-with-rebase-i-in-c'
"rebase" that has been rewritten learns the new calling convention used by "rebase -i" that was rewritten in C, tying the loose end between two GSoC topics that stomped on each other's toes. * js/rebase-in-c-5.5-work-with-rebase-i-in-c: builtin rebase: prepare for builtin rebase -i
2 parents fd1a9e9 + bc24382 commit 4b3517e

File tree

1 file changed

+83
-4
lines changed

1 file changed

+83
-4
lines changed

builtin/rebase.c

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,93 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
327327
}
328328
}
329329

330+
static const char *resolvemsg =
331+
N_("Resolve all conflicts manually, mark them as resolved with\n"
332+
"\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n"
333+
"You can instead skip this commit: run \"git rebase --skip\".\n"
334+
"To abort and get back to the state before \"git rebase\", run "
335+
"\"git rebase --abort\".");
336+
330337
static int run_specific_rebase(struct rebase_options *opts)
331338
{
332339
const char *argv[] = { NULL, NULL };
333340
struct strbuf script_snippet = STRBUF_INIT;
334341
int status;
335342
const char *backend, *backend_func;
336343

344+
if (opts->type == REBASE_INTERACTIVE) {
345+
/* Run builtin interactive rebase */
346+
struct child_process child = CHILD_PROCESS_INIT;
347+
348+
argv_array_pushf(&child.env_array, "GIT_CHERRY_PICK_HELP=%s",
349+
resolvemsg);
350+
if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
351+
argv_array_push(&child.env_array, "GIT_EDITOR=:");
352+
opts->autosquash = 0;
353+
}
354+
355+
child.git_cmd = 1;
356+
argv_array_push(&child.args, "rebase--interactive");
357+
358+
if (opts->action)
359+
argv_array_pushf(&child.args, "--%s", opts->action);
360+
if (opts->keep_empty)
361+
argv_array_push(&child.args, "--keep-empty");
362+
if (opts->rebase_merges)
363+
argv_array_push(&child.args, "--rebase-merges");
364+
if (opts->rebase_cousins)
365+
argv_array_push(&child.args, "--rebase-cousins");
366+
if (opts->autosquash)
367+
argv_array_push(&child.args, "--autosquash");
368+
if (opts->flags & REBASE_VERBOSE)
369+
argv_array_push(&child.args, "--verbose");
370+
if (opts->flags & REBASE_FORCE)
371+
argv_array_push(&child.args, "--no-ff");
372+
if (opts->restrict_revision)
373+
argv_array_pushf(&child.args,
374+
"--restrict-revision=^%s",
375+
oid_to_hex(&opts->restrict_revision->object.oid));
376+
if (opts->upstream)
377+
argv_array_pushf(&child.args, "--upstream=%s",
378+
oid_to_hex(&opts->upstream->object.oid));
379+
if (opts->onto)
380+
argv_array_pushf(&child.args, "--onto=%s",
381+
oid_to_hex(&opts->onto->object.oid));
382+
if (opts->squash_onto)
383+
argv_array_pushf(&child.args, "--squash-onto=%s",
384+
oid_to_hex(opts->squash_onto));
385+
if (opts->onto_name)
386+
argv_array_pushf(&child.args, "--onto-name=%s",
387+
opts->onto_name);
388+
argv_array_pushf(&child.args, "--head-name=%s",
389+
opts->head_name ?
390+
opts->head_name : "detached HEAD");
391+
if (opts->strategy)
392+
argv_array_pushf(&child.args, "--strategy=%s",
393+
opts->strategy);
394+
if (opts->strategy_opts)
395+
argv_array_pushf(&child.args, "--strategy-opts=%s",
396+
opts->strategy_opts);
397+
if (opts->switch_to)
398+
argv_array_pushf(&child.args, "--switch-to=%s",
399+
opts->switch_to);
400+
if (opts->cmd)
401+
argv_array_pushf(&child.args, "--cmd=%s", opts->cmd);
402+
if (opts->allow_empty_message)
403+
argv_array_push(&child.args, "--allow-empty-message");
404+
if (opts->allow_rerere_autoupdate > 0)
405+
argv_array_push(&child.args, "--rerere-autoupdate");
406+
else if (opts->allow_rerere_autoupdate == 0)
407+
argv_array_push(&child.args, "--no-rerere-autoupdate");
408+
if (opts->gpg_sign_opt)
409+
argv_array_push(&child.args, opts->gpg_sign_opt);
410+
if (opts->signoff)
411+
argv_array_push(&child.args, "--signoff");
412+
413+
status = run_command(&child);
414+
goto finished_rebase;
415+
}
416+
337417
add_var(&script_snippet, "GIT_DIR", absolute_path(get_git_dir()));
338418
add_var(&script_snippet, "state_dir", opts->state_dir);
339419

@@ -396,10 +476,6 @@ static int run_specific_rebase(struct rebase_options *opts)
396476
backend = "git-rebase--am";
397477
backend_func = "git_rebase__am";
398478
break;
399-
case REBASE_INTERACTIVE:
400-
backend = "git-rebase--interactive";
401-
backend_func = "git_rebase__interactive";
402-
break;
403479
case REBASE_MERGE:
404480
backend = "git-rebase--merge";
405481
backend_func = "git_rebase__merge";
@@ -419,8 +495,11 @@ static int run_specific_rebase(struct rebase_options *opts)
419495
argv[0] = script_snippet.buf;
420496

421497
status = run_command_v_opt(argv, RUN_USING_SHELL);
498+
finished_rebase:
422499
if (opts->dont_finish_rebase)
423500
; /* do nothing */
501+
else if (opts->type == REBASE_INTERACTIVE)
502+
; /* interactive rebase cleans up after itself */
424503
else if (status == 0) {
425504
if (!file_exists(state_dir_path("stopped-sha", opts)))
426505
finish_rebase(opts);

0 commit comments

Comments
 (0)