} flags;
struct strbuf git_am_opt;
const char *action;
+ int signoff;
+ int allow_rerere_autoupdate;
};
static int is_interactive(struct rebase_options *opts)
if (file_exists(state_dir_path("verbose", opts)))
opts->flags |= REBASE_VERBOSE;
+ if (file_exists(state_dir_path("signoff", opts))) {
+ opts->signoff = 1;
+ opts->flags |= REBASE_FORCE;
+ }
+
+ if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) {
+ strbuf_reset(&buf);
+ if (read_one(state_dir_path("allow_rerere_autoupdate", opts),
+ &buf))
+ return -1;
+ if (!strcmp(buf.buf, "--rerere-autoupdate"))
+ opts->allow_rerere_autoupdate = 1;
+ else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
+ opts->allow_rerere_autoupdate = 0;
+ else
+ warning(_("ignoring invalid allow_rerere_autoupdate: "
+ "'%s'"), buf.buf);
+ } else
+ opts->allow_rerere_autoupdate = -1;
+
strbuf_release(&buf);
return 0;
if (opts->switch_to)
add_var(&script_snippet, "switch_to", opts->switch_to);
add_var(&script_snippet, "action", opts->action ? opts->action : "");
+ add_var(&script_snippet, "signoff", opts->signoff ? "--signoff" : "");
+ add_var(&script_snippet, "allow_rerere_autoupdate",
+ opts->allow_rerere_autoupdate < 0 ? "" :
+ opts->allow_rerere_autoupdate ?
+ "--rerere-autoupdate" : "--no-rerere-autoupdate");
switch (opts->type) {
case REBASE_AM:
return res && is_linear_history(onto, head);
}
+/* -i followed by -m is still -i */
+static int parse_opt_merge(const struct option *opt, const char *arg, int unset)
+{
+ struct rebase_options *opts = opt->value;
+
+ if (!is_interactive(opts))
+ opts->type = REBASE_MERGE;
+
+ return 0;
+}
+
+/* -i followed by -p is still explicitly interactive, but -p alone is not */
+static int parse_opt_interactive(const struct option *opt, const char *arg,
+ int unset)
+{
+ struct rebase_options *opts = opt->value;
+
+ opts->type = REBASE_INTERACTIVE;
+ opts->flags |= REBASE_INTERACTIVE_EXPLICIT;
+
+ return 0;
+}
+
int cmd_rebase(int argc, const char **argv, const char *prefix)
{
struct rebase_options options = {
.type = REBASE_UNSPECIFIED,
.flags = REBASE_NO_QUIET,
.git_am_opt = STRBUF_INIT,
+ .allow_rerere_autoupdate = -1,
};
const char *branch_name;
int ret, flags, total_argc, in_progress = 0;
ACTION_CONTINUE,
ACTION_SKIP,
ACTION_ABORT,
+ ACTION_QUIT,
+ ACTION_EDIT_TODO,
+ ACTION_SHOW_CURRENT_PATCH,
} action = NO_ACTION;
+ int committer_date_is_author_date = 0;
struct option builtin_rebase_options[] = {
OPT_STRING(0, "onto", &options.onto_name,
N_("revision"),
{OPTION_NEGBIT, 'n', "no-stat", &options.flags, NULL,
N_("do not show diffstat of what changed upstream"),
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
+ OPT_BOOL(0, "signoff", &options.signoff,
+ N_("add a Signed-off-by: line to each commit")),
+ OPT_BOOL(0, "committer-date-is-author-date",
+ &committer_date_is_author_date,
+ N_("passed to 'git am'")),
OPT_BIT('f', "force-rebase", &options.flags,
N_("cherry-pick all commits, even if unchanged"),
REBASE_FORCE),
OPT_CMDMODE(0, "abort", &action,
N_("abort and check out the original branch"),
ACTION_ABORT),
+ OPT_CMDMODE(0, "quit", &action,
+ N_("abort but keep HEAD where it is"), ACTION_QUIT),
+ OPT_CMDMODE(0, "edit-todo", &action, N_("edit the todo list "
+ "during an interactive rebase"), ACTION_EDIT_TODO),
+ OPT_CMDMODE(0, "show-current-patch", &action,
+ N_("show the patch file being applied or merged"),
+ ACTION_SHOW_CURRENT_PATCH),
+ { OPTION_CALLBACK, 'm', "merge", &options, NULL,
+ N_("use merging strategies to rebase"),
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ parse_opt_merge },
+ { OPTION_CALLBACK, 'i', "interactive", &options, NULL,
+ N_("let the user edit the list of commits to rebase"),
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ parse_opt_interactive },
+ OPT_SET_INT('p', "preserve-merges", &options.type,
+ N_("try to recreate merges instead of ignoring "
+ "them"), REBASE_PRESERVE_MERGES),
+ OPT_BOOL(0, "rerere-autoupdate",
+ &options.allow_rerere_autoupdate,
+ N_("allow rerere to update index with resolved "
+ "conflict")),
OPT_END(),
};
git_config(rebase_config, &options);
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "%s/applying", apply_dir());
+ if(file_exists(buf.buf))
+ die(_("It looks like 'git am' is in progress. Cannot rebase."));
+
if (is_directory(apply_dir())) {
options.type = REBASE_AM;
options.state_dir = apply_dir();
usage_with_options(builtin_rebase_usage,
builtin_rebase_options);
+ if (action != NO_ACTION && !in_progress)
+ die(_("No rebase in progress?"));
+
+ if (action == ACTION_EDIT_TODO && !is_interactive(&options))
+ die(_("The --edit-todo action can only be used during "
+ "interactive rebase."));
+
switch (action) {
case ACTION_CONTINUE: {
struct object_id head;
ret = finish_rebase(&options);
goto cleanup;
}
+ case ACTION_QUIT: {
+ strbuf_reset(&buf);
+ strbuf_addstr(&buf, options.state_dir);
+ ret = !!remove_dir_recursively(&buf, 0);
+ if (ret)
+ die(_("could not remove '%s'"), options.state_dir);
+ goto cleanup;
+ }
+ case ACTION_EDIT_TODO:
+ options.action = "edit-todo";
+ options.dont_finish_rebase = 1;
+ goto run_rebase;
+ case ACTION_SHOW_CURRENT_PATCH:
+ options.action = "show-current-patch";
+ options.dont_finish_rebase = 1;
+ goto run_rebase;
+ case NO_ACTION:
+ break;
default:
- die("TODO");
+ BUG("action: %d", action);
}
/* Make sure no rebase is in progress */
if (!(options.flags & REBASE_NO_QUIET))
strbuf_addstr(&options.git_am_opt, " -q");
+ if (committer_date_is_author_date) {
+ strbuf_addstr(&options.git_am_opt,
+ " --committer-date-is-author-date");
+ options.flags |= REBASE_FORCE;
+ }
+
switch (options.type) {
case REBASE_MERGE:
case REBASE_INTERACTIVE:
break;
}
+ if (options.signoff) {
+ if (options.type == REBASE_PRESERVE_MERGES)
+ die("cannot combine '--signoff' with "
+ "'--preserve-merges'");
+ strbuf_addstr(&options.git_am_opt, " --signoff");
+ options.flags |= REBASE_FORCE;
+ }
+
if (!options.root) {
if (argc < 1)
die("TODO: handle @{upstream}");
diff_flush(&opts);
}
+ if (is_interactive(&options))
+ goto run_rebase;
+
/* Detach HEAD and reset the tree */
if (options.flags & REBASE_NO_QUIET)
printf(_("First, rewinding head to replay your work on top of "