Merge branch 'pw/rebase-reflog-fixes'
Fix some bugs in the reflog messages when rebasing and changes the reflog messages of "rebase --apply" to match "rebase --merge" with the aim of making the reflog easier to parse. * pw/rebase-reflog-fixes: rebase: cleanup action handling rebase --abort: improve reflog message rebase --apply: make reflog messages match rebase --merge rebase --apply: respect GIT_REFLOG_ACTION rebase --merge: fix reflog message after skipping rebase --merge: fix reflog when continuing t3406: rework rebase reflog tests rebase --apply: remove duplicated code
This commit is contained in:
146
builtin/rebase.c
146
builtin/rebase.c
@ -59,6 +59,26 @@ enum empty_type {
|
|||||||
EMPTY_ASK
|
EMPTY_ASK
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum action {
|
||||||
|
ACTION_NONE = 0,
|
||||||
|
ACTION_CONTINUE,
|
||||||
|
ACTION_SKIP,
|
||||||
|
ACTION_ABORT,
|
||||||
|
ACTION_QUIT,
|
||||||
|
ACTION_EDIT_TODO,
|
||||||
|
ACTION_SHOW_CURRENT_PATCH
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *action_names[] = {
|
||||||
|
"undefined",
|
||||||
|
"continue",
|
||||||
|
"skip",
|
||||||
|
"abort",
|
||||||
|
"quit",
|
||||||
|
"edit_todo",
|
||||||
|
"show_current_patch"
|
||||||
|
};
|
||||||
|
|
||||||
struct rebase_options {
|
struct rebase_options {
|
||||||
enum rebase_type type;
|
enum rebase_type type;
|
||||||
enum empty_type empty;
|
enum empty_type empty;
|
||||||
@ -85,7 +105,7 @@ struct rebase_options {
|
|||||||
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
|
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
|
||||||
} flags;
|
} flags;
|
||||||
struct strvec git_am_opts;
|
struct strvec git_am_opts;
|
||||||
const char *action;
|
enum action action;
|
||||||
int signoff;
|
int signoff;
|
||||||
int allow_rerere_autoupdate;
|
int allow_rerere_autoupdate;
|
||||||
int keep_empty;
|
int keep_empty;
|
||||||
@ -157,24 +177,6 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
|
|||||||
return replay;
|
return replay;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum action {
|
|
||||||
ACTION_NONE = 0,
|
|
||||||
ACTION_CONTINUE,
|
|
||||||
ACTION_SKIP,
|
|
||||||
ACTION_ABORT,
|
|
||||||
ACTION_QUIT,
|
|
||||||
ACTION_EDIT_TODO,
|
|
||||||
ACTION_SHOW_CURRENT_PATCH
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *action_names[] = { "undefined",
|
|
||||||
"continue",
|
|
||||||
"skip",
|
|
||||||
"abort",
|
|
||||||
"quit",
|
|
||||||
"edit_todo",
|
|
||||||
"show_current_patch" };
|
|
||||||
|
|
||||||
static int edit_todo_file(unsigned flags)
|
static int edit_todo_file(unsigned flags)
|
||||||
{
|
{
|
||||||
const char *todo_file = rebase_path_todo();
|
const char *todo_file = rebase_path_todo();
|
||||||
@ -311,8 +313,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_sequencer_rebase(struct rebase_options *opts,
|
static int run_sequencer_rebase(struct rebase_options *opts)
|
||||||
enum action command)
|
|
||||||
{
|
{
|
||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
int abbreviate_commands = 0, ret = 0;
|
int abbreviate_commands = 0, ret = 0;
|
||||||
@ -327,7 +328,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
|
|||||||
flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0;
|
flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0;
|
||||||
flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0;
|
flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0;
|
||||||
|
|
||||||
switch (command) {
|
switch (opts->action) {
|
||||||
case ACTION_NONE: {
|
case ACTION_NONE: {
|
||||||
if (!opts->onto && !opts->upstream)
|
if (!opts->onto && !opts->upstream)
|
||||||
die(_("a base commit must be provided with --upstream or --onto"));
|
die(_("a base commit must be provided with --upstream or --onto"));
|
||||||
@ -360,7 +361,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BUG("invalid command '%d'", command);
|
BUG("invalid command '%d'", opts->action);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -583,10 +584,11 @@ static int move_to_original_branch(struct rebase_options *opts)
|
|||||||
if (!opts->onto)
|
if (!opts->onto)
|
||||||
BUG("move_to_original_branch without onto");
|
BUG("move_to_original_branch without onto");
|
||||||
|
|
||||||
strbuf_addf(&branch_reflog, "rebase finished: %s onto %s",
|
strbuf_addf(&branch_reflog, "%s (finish): %s onto %s",
|
||||||
|
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
|
||||||
opts->head_name, oid_to_hex(&opts->onto->object.oid));
|
opts->head_name, oid_to_hex(&opts->onto->object.oid));
|
||||||
strbuf_addf(&head_reflog, "rebase finished: returning to %s",
|
strbuf_addf(&head_reflog, "%s (finish): returning to %s",
|
||||||
opts->head_name);
|
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name);
|
||||||
ropts.branch = opts->head_name;
|
ropts.branch = opts->head_name;
|
||||||
ropts.flags = RESET_HEAD_REFS_ONLY;
|
ropts.flags = RESET_HEAD_REFS_ONLY;
|
||||||
ropts.branch_msg = branch_reflog.buf;
|
ropts.branch_msg = branch_reflog.buf;
|
||||||
@ -615,8 +617,9 @@ static int run_am(struct rebase_options *opts)
|
|||||||
|
|
||||||
am.git_cmd = 1;
|
am.git_cmd = 1;
|
||||||
strvec_push(&am.args, "am");
|
strvec_push(&am.args, "am");
|
||||||
|
strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
|
||||||
if (opts->action && !strcmp("continue", opts->action)) {
|
getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
|
||||||
|
if (opts->action == ACTION_CONTINUE) {
|
||||||
strvec_push(&am.args, "--resolved");
|
strvec_push(&am.args, "--resolved");
|
||||||
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
||||||
if (opts->gpg_sign_opt)
|
if (opts->gpg_sign_opt)
|
||||||
@ -627,7 +630,7 @@ static int run_am(struct rebase_options *opts)
|
|||||||
|
|
||||||
return move_to_original_branch(opts);
|
return move_to_original_branch(opts);
|
||||||
}
|
}
|
||||||
if (opts->action && !strcmp("skip", opts->action)) {
|
if (opts->action == ACTION_SKIP) {
|
||||||
strvec_push(&am.args, "--skip");
|
strvec_push(&am.args, "--skip");
|
||||||
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
|
||||||
status = run_command(&am);
|
status = run_command(&am);
|
||||||
@ -636,7 +639,7 @@ static int run_am(struct rebase_options *opts)
|
|||||||
|
|
||||||
return move_to_original_branch(opts);
|
return move_to_original_branch(opts);
|
||||||
}
|
}
|
||||||
if (opts->action && !strcmp("show-current-patch", opts->action)) {
|
if (opts->action == ACTION_SHOW_CURRENT_PATCH) {
|
||||||
strvec_push(&am.args, "--show-current-patch");
|
strvec_push(&am.args, "--show-current-patch");
|
||||||
return run_command(&am);
|
return run_command(&am);
|
||||||
}
|
}
|
||||||
@ -729,7 +732,7 @@ static int run_am(struct rebase_options *opts)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_specific_rebase(struct rebase_options *opts, enum action action)
|
static int run_specific_rebase(struct rebase_options *opts)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -747,7 +750,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action)
|
|||||||
opts->gpg_sign_opt = tmp;
|
opts->gpg_sign_opt = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = run_sequencer_rebase(opts, action);
|
status = run_sequencer_rebase(opts);
|
||||||
} else if (opts->type == REBASE_APPLY)
|
} else if (opts->type == REBASE_APPLY)
|
||||||
status = run_am(opts);
|
status = run_am(opts);
|
||||||
else
|
else
|
||||||
@ -1005,23 +1008,6 @@ static void NORETURN error_on_missing_default_upstream(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_reflog_action(struct rebase_options *options)
|
|
||||||
{
|
|
||||||
const char *env;
|
|
||||||
struct strbuf buf = STRBUF_INIT;
|
|
||||||
|
|
||||||
if (!is_merge(options))
|
|
||||||
return;
|
|
||||||
|
|
||||||
env = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
|
|
||||||
if (env && strcmp("rebase", env))
|
|
||||||
return; /* only override it if it is "rebase" */
|
|
||||||
|
|
||||||
strbuf_addf(&buf, "rebase (%s)", options->action);
|
|
||||||
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, buf.buf, 1);
|
|
||||||
strbuf_release(&buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int check_exec_cmd(const char *cmd)
|
static int check_exec_cmd(const char *cmd)
|
||||||
{
|
{
|
||||||
if (strchr(cmd, '\n'))
|
if (strchr(cmd, '\n'))
|
||||||
@ -1046,7 +1032,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct object_id branch_base;
|
struct object_id branch_base;
|
||||||
int ignore_whitespace = 0;
|
int ignore_whitespace = 0;
|
||||||
enum action action = ACTION_NONE;
|
|
||||||
const char *gpg_sign = NULL;
|
const char *gpg_sign = NULL;
|
||||||
struct string_list exec = STRING_LIST_INIT_NODUP;
|
struct string_list exec = STRING_LIST_INIT_NODUP;
|
||||||
const char *rebase_merges = NULL;
|
const char *rebase_merges = NULL;
|
||||||
@ -1095,18 +1080,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_BIT(0, "no-ff", &options.flags,
|
OPT_BIT(0, "no-ff", &options.flags,
|
||||||
N_("cherry-pick all commits, even if unchanged"),
|
N_("cherry-pick all commits, even if unchanged"),
|
||||||
REBASE_FORCE),
|
REBASE_FORCE),
|
||||||
OPT_CMDMODE(0, "continue", &action, N_("continue"),
|
OPT_CMDMODE(0, "continue", &options.action, N_("continue"),
|
||||||
ACTION_CONTINUE),
|
ACTION_CONTINUE),
|
||||||
OPT_CMDMODE(0, "skip", &action,
|
OPT_CMDMODE(0, "skip", &options.action,
|
||||||
N_("skip current patch and continue"), ACTION_SKIP),
|
N_("skip current patch and continue"), ACTION_SKIP),
|
||||||
OPT_CMDMODE(0, "abort", &action,
|
OPT_CMDMODE(0, "abort", &options.action,
|
||||||
N_("abort and check out the original branch"),
|
N_("abort and check out the original branch"),
|
||||||
ACTION_ABORT),
|
ACTION_ABORT),
|
||||||
OPT_CMDMODE(0, "quit", &action,
|
OPT_CMDMODE(0, "quit", &options.action,
|
||||||
N_("abort but keep HEAD where it is"), ACTION_QUIT),
|
N_("abort but keep HEAD where it is"), ACTION_QUIT),
|
||||||
OPT_CMDMODE(0, "edit-todo", &action, N_("edit the todo list "
|
OPT_CMDMODE(0, "edit-todo", &options.action, N_("edit the todo list "
|
||||||
"during an interactive rebase"), ACTION_EDIT_TODO),
|
"during an interactive rebase"), ACTION_EDIT_TODO),
|
||||||
OPT_CMDMODE(0, "show-current-patch", &action,
|
OPT_CMDMODE(0, "show-current-patch", &options.action,
|
||||||
N_("show the patch file being applied or merged"),
|
N_("show the patch file being applied or merged"),
|
||||||
ACTION_SHOW_CURRENT_PATCH),
|
ACTION_SHOW_CURRENT_PATCH),
|
||||||
OPT_CALLBACK_F(0, "apply", &options, NULL,
|
OPT_CALLBACK_F(0, "apply", &options, NULL,
|
||||||
@ -1198,7 +1183,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
} else if (is_directory(merge_dir())) {
|
} else if (is_directory(merge_dir())) {
|
||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
strbuf_addf(&buf, "%s/rewritten", merge_dir());
|
strbuf_addf(&buf, "%s/rewritten", merge_dir());
|
||||||
if (!(action == ACTION_ABORT) && is_directory(buf.buf)) {
|
if (!(options.action == ACTION_ABORT) && is_directory(buf.buf)) {
|
||||||
die(_("`rebase --preserve-merges` (-p) is no longer supported.\n"
|
die(_("`rebase --preserve-merges` (-p) is no longer supported.\n"
|
||||||
"Use `git rebase --abort` to terminate current rebase.\n"
|
"Use `git rebase --abort` to terminate current rebase.\n"
|
||||||
"Or downgrade to v2.33, or earlier, to complete the rebase."));
|
"Or downgrade to v2.33, or earlier, to complete the rebase."));
|
||||||
@ -1225,7 +1210,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
"Note: Your `pull.rebase` configuration may also be set to 'preserve',\n"
|
"Note: Your `pull.rebase` configuration may also be set to 'preserve',\n"
|
||||||
"which is no longer supported; use 'merges' instead"));
|
"which is no longer supported; use 'merges' instead"));
|
||||||
|
|
||||||
if (action != ACTION_NONE && total_argc != 2) {
|
if (options.action != ACTION_NONE && total_argc != 2) {
|
||||||
usage_with_options(builtin_rebase_usage,
|
usage_with_options(builtin_rebase_usage,
|
||||||
builtin_rebase_options);
|
builtin_rebase_options);
|
||||||
}
|
}
|
||||||
@ -1256,11 +1241,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
if (options.root && options.fork_point > 0)
|
if (options.root && options.fork_point > 0)
|
||||||
die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point");
|
die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point");
|
||||||
|
|
||||||
if (action != ACTION_NONE && !in_progress)
|
if (options.action != ACTION_NONE && !in_progress)
|
||||||
die(_("No rebase in progress?"));
|
die(_("No rebase in progress?"));
|
||||||
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
|
setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0);
|
||||||
|
|
||||||
if (action == ACTION_EDIT_TODO && !is_merge(&options))
|
if (options.action == ACTION_EDIT_TODO && !is_merge(&options))
|
||||||
die(_("The --edit-todo action can only be used during "
|
die(_("The --edit-todo action can only be used during "
|
||||||
"interactive rebase."));
|
"interactive rebase."));
|
||||||
|
|
||||||
@ -1270,18 +1255,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
else if (exec.nr)
|
else if (exec.nr)
|
||||||
trace2_cmd_mode("interactive-exec");
|
trace2_cmd_mode("interactive-exec");
|
||||||
else
|
else
|
||||||
trace2_cmd_mode(action_names[action]);
|
trace2_cmd_mode(action_names[options.action]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action) {
|
switch (options.action) {
|
||||||
case ACTION_CONTINUE: {
|
case ACTION_CONTINUE: {
|
||||||
struct object_id head;
|
struct object_id head;
|
||||||
struct lock_file lock_file = LOCK_INIT;
|
struct lock_file lock_file = LOCK_INIT;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
options.action = "continue";
|
|
||||||
set_reflog_action(&options);
|
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (get_oid("HEAD", &head))
|
if (get_oid("HEAD", &head))
|
||||||
die(_("Cannot read HEAD"));
|
die(_("Cannot read HEAD"));
|
||||||
@ -1307,9 +1289,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
case ACTION_SKIP: {
|
case ACTION_SKIP: {
|
||||||
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
||||||
|
|
||||||
options.action = "skip";
|
|
||||||
set_reflog_action(&options);
|
|
||||||
|
|
||||||
rerere_clear(the_repository, &merge_rr);
|
rerere_clear(the_repository, &merge_rr);
|
||||||
string_list_clear(&merge_rr, 1);
|
string_list_clear(&merge_rr, 1);
|
||||||
ropts.flags = RESET_HEAD_HARD;
|
ropts.flags = RESET_HEAD_HARD;
|
||||||
@ -1322,18 +1301,22 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
case ACTION_ABORT: {
|
case ACTION_ABORT: {
|
||||||
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
||||||
options.action = "abort";
|
struct strbuf head_msg = STRBUF_INIT;
|
||||||
set_reflog_action(&options);
|
|
||||||
|
|
||||||
rerere_clear(the_repository, &merge_rr);
|
rerere_clear(the_repository, &merge_rr);
|
||||||
string_list_clear(&merge_rr, 1);
|
string_list_clear(&merge_rr, 1);
|
||||||
|
|
||||||
if (read_basic_state(&options))
|
if (read_basic_state(&options))
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
strbuf_addf(&head_msg, "%s (abort): returning to %s",
|
||||||
|
getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
|
||||||
|
options.head_name ? options.head_name
|
||||||
|
: oid_to_hex(&options.orig_head->object.oid));
|
||||||
ropts.oid = &options.orig_head->object.oid;
|
ropts.oid = &options.orig_head->object.oid;
|
||||||
|
ropts.head_msg = head_msg.buf;
|
||||||
ropts.branch = options.head_name;
|
ropts.branch = options.head_name;
|
||||||
ropts.flags = RESET_HEAD_HARD;
|
ropts.flags = RESET_HEAD_HARD;
|
||||||
ropts.default_reflog_action = DEFAULT_REFLOG_ACTION;
|
|
||||||
if (reset_head(the_repository, &ropts) < 0)
|
if (reset_head(the_repository, &ropts) < 0)
|
||||||
die(_("could not move back to %s"),
|
die(_("could not move back to %s"),
|
||||||
oid_to_hex(&options.orig_head->object.oid));
|
oid_to_hex(&options.orig_head->object.oid));
|
||||||
@ -1359,17 +1342,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
case ACTION_EDIT_TODO:
|
case ACTION_EDIT_TODO:
|
||||||
options.action = "edit-todo";
|
|
||||||
options.dont_finish_rebase = 1;
|
options.dont_finish_rebase = 1;
|
||||||
goto run_rebase;
|
goto run_rebase;
|
||||||
case ACTION_SHOW_CURRENT_PATCH:
|
case ACTION_SHOW_CURRENT_PATCH:
|
||||||
options.action = "show-current-patch";
|
|
||||||
options.dont_finish_rebase = 1;
|
options.dont_finish_rebase = 1;
|
||||||
goto run_rebase;
|
goto run_rebase;
|
||||||
case ACTION_NONE:
|
case ACTION_NONE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BUG("action: %d", action);
|
BUG("action: %d", options.action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure no rebase is in progress */
|
/* Make sure no rebase is in progress */
|
||||||
@ -1393,7 +1374,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
|
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
|
||||||
(action != ACTION_NONE) ||
|
(options.action != ACTION_NONE) ||
|
||||||
(exec.nr > 0) ||
|
(exec.nr > 0) ||
|
||||||
options.autosquash) {
|
options.autosquash) {
|
||||||
allow_preemptive_ff = 0;
|
allow_preemptive_ff = 0;
|
||||||
@ -1804,7 +1785,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
printf(_("First, rewinding head to replay your work on top of "
|
printf(_("First, rewinding head to replay your work on top of "
|
||||||
"it...\n"));
|
"it...\n"));
|
||||||
|
|
||||||
strbuf_addf(&msg, "%s: checkout %s",
|
strbuf_addf(&msg, "%s (start): checkout %s",
|
||||||
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
|
getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
|
||||||
ropts.oid = &options.onto->object.oid;
|
ropts.oid = &options.onto->object.oid;
|
||||||
ropts.orig_head = &options.orig_head->object.oid,
|
ropts.orig_head = &options.orig_head->object.oid,
|
||||||
@ -1820,19 +1801,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
* If the onto is a proper descendant of the tip of the branch, then
|
* If the onto is a proper descendant of the tip of the branch, then
|
||||||
* we just fast-forwarded.
|
* we just fast-forwarded.
|
||||||
*/
|
*/
|
||||||
strbuf_reset(&msg);
|
|
||||||
if (oideq(&branch_base, &options.orig_head->object.oid)) {
|
if (oideq(&branch_base, &options.orig_head->object.oid)) {
|
||||||
printf(_("Fast-forwarded %s to %s.\n"),
|
printf(_("Fast-forwarded %s to %s.\n"),
|
||||||
branch_name, options.onto_name);
|
branch_name, options.onto_name);
|
||||||
strbuf_addf(&msg, "rebase finished: %s onto %s",
|
move_to_original_branch(&options);
|
||||||
options.head_name ? options.head_name : "detached HEAD",
|
|
||||||
oid_to_hex(&options.onto->object.oid));
|
|
||||||
memset(&ropts, 0, sizeof(ropts));
|
|
||||||
ropts.branch = options.head_name;
|
|
||||||
ropts.flags = RESET_HEAD_REFS_ONLY;
|
|
||||||
ropts.head_msg = msg.buf;
|
|
||||||
reset_head(the_repository, &ropts);
|
|
||||||
strbuf_release(&msg);
|
|
||||||
ret = finish_rebase(&options);
|
ret = finish_rebase(&options);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1847,7 +1819,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
options.revisions = revisions.buf;
|
options.revisions = revisions.buf;
|
||||||
|
|
||||||
run_rebase:
|
run_rebase:
|
||||||
ret = run_specific_rebase(&options, action);
|
ret = run_specific_rebase(&options);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
|
@ -5050,6 +5050,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
|
|||||||
if (read_populate_opts(opts))
|
if (read_populate_opts(opts))
|
||||||
return -1;
|
return -1;
|
||||||
if (is_rebase_i(opts)) {
|
if (is_rebase_i(opts)) {
|
||||||
|
char *previous_reflog_action;
|
||||||
|
|
||||||
if ((res = read_populate_todo(r, &todo_list, opts)))
|
if ((res = read_populate_todo(r, &todo_list, opts)))
|
||||||
goto release_todo_list;
|
goto release_todo_list;
|
||||||
|
|
||||||
@ -5060,10 +5062,13 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
|
|||||||
unlink(rebase_path_dropped());
|
unlink(rebase_path_dropped());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
|
||||||
|
setenv(GIT_REFLOG_ACTION, reflog_message(opts, "continue", NULL), 1);
|
||||||
if (commit_staged_changes(r, opts, &todo_list)) {
|
if (commit_staged_changes(r, opts, &todo_list)) {
|
||||||
res = -1;
|
res = -1;
|
||||||
goto release_todo_list;
|
goto release_todo_list;
|
||||||
}
|
}
|
||||||
|
setenv(GIT_REFLOG_ACTION, previous_reflog_action, 1);
|
||||||
} else if (!file_exists(get_todo_path(opts)))
|
} else if (!file_exists(get_todo_path(opts)))
|
||||||
return continue_single_pick(r, opts);
|
return continue_single_pick(r, opts);
|
||||||
else if ((res = read_populate_todo(r, &todo_list, opts)))
|
else if ((res = read_populate_todo(r, &todo_list, opts)))
|
||||||
|
@ -10,10 +10,16 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|||||||
test_expect_success 'setup' '
|
test_expect_success 'setup' '
|
||||||
test_commit O fileO &&
|
test_commit O fileO &&
|
||||||
test_commit X fileX &&
|
test_commit X fileX &&
|
||||||
|
git branch fast-forward &&
|
||||||
test_commit A fileA &&
|
test_commit A fileA &&
|
||||||
test_commit B fileB &&
|
test_commit B fileB &&
|
||||||
test_commit Y fileY &&
|
test_commit Y fileY &&
|
||||||
|
|
||||||
|
git checkout -b conflicts O &&
|
||||||
|
test_commit P &&
|
||||||
|
test_commit conflict-X fileX &&
|
||||||
|
test_commit Q &&
|
||||||
|
|
||||||
git checkout -b topic O &&
|
git checkout -b topic O &&
|
||||||
git cherry-pick A B &&
|
git cherry-pick A B &&
|
||||||
test_commit Z fileZ &&
|
test_commit Z fileZ &&
|
||||||
@ -79,54 +85,165 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
|
|||||||
test_i18ngrep "Invalid whitespace option" err
|
test_i18ngrep "Invalid whitespace option" err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'GIT_REFLOG_ACTION' '
|
write_reflog_expect () {
|
||||||
git checkout start &&
|
if test $mode = --apply
|
||||||
test_commit reflog-onto &&
|
then
|
||||||
git checkout -b reflog-topic start &&
|
sed 's/(continue)/(pick)/'
|
||||||
test_commit reflog-to-rebase &&
|
else
|
||||||
|
cat
|
||||||
|
fi >expect
|
||||||
|
}
|
||||||
|
|
||||||
git rebase reflog-onto &&
|
test_reflog () {
|
||||||
git log -g --format=%gs -3 >actual &&
|
mode=$1
|
||||||
cat >expect <<-\EOF &&
|
reflog_action="$2"
|
||||||
rebase (finish): returning to refs/heads/reflog-topic
|
|
||||||
rebase (pick): reflog-to-rebase
|
test_expect_success "rebase $mode reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
|
||||||
rebase (start): checkout reflog-onto
|
git checkout conflicts &&
|
||||||
|
test_when_finished "git reset --hard Q" &&
|
||||||
|
|
||||||
|
(
|
||||||
|
if test -n "$reflog_action"
|
||||||
|
then
|
||||||
|
GIT_REFLOG_ACTION="$reflog_action" &&
|
||||||
|
export GIT_REFLOG_ACTION
|
||||||
|
fi &&
|
||||||
|
test_must_fail git rebase $mode main &&
|
||||||
|
echo resolved >fileX &&
|
||||||
|
git add fileX &&
|
||||||
|
git rebase --continue
|
||||||
|
) &&
|
||||||
|
|
||||||
|
git log -g --format=%gs -5 >actual &&
|
||||||
|
write_reflog_expect <<-EOF &&
|
||||||
|
${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
|
||||||
|
${reflog_action:-rebase} (pick): Q
|
||||||
|
${reflog_action:-rebase} (continue): conflict-X
|
||||||
|
${reflog_action:-rebase} (pick): P
|
||||||
|
${reflog_action:-rebase} (start): checkout main
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect actual &&
|
test_cmp expect actual &&
|
||||||
|
|
||||||
git checkout -b reflog-prefix reflog-to-rebase &&
|
git log -g --format=%gs -1 conflicts >actual &&
|
||||||
GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
|
write_reflog_expect <<-EOF &&
|
||||||
git log -g --format=%gs -3 >actual &&
|
${reflog_action:-rebase} (finish): refs/heads/conflicts onto $(git rev-parse main)
|
||||||
cat >expect <<-\EOF &&
|
|
||||||
change-the-reflog (finish): returning to refs/heads/reflog-prefix
|
|
||||||
change-the-reflog (pick): reflog-to-rebase
|
|
||||||
change-the-reflog (start): checkout reflog-onto
|
|
||||||
EOF
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success 'rebase --apply reflog' '
|
|
||||||
git checkout -b reflog-apply start &&
|
|
||||||
old_head_reflog="$(git log -g --format=%gs -1 HEAD)" &&
|
|
||||||
|
|
||||||
git rebase --apply Y &&
|
|
||||||
|
|
||||||
git log -g --format=%gs -4 HEAD >actual &&
|
|
||||||
cat >expect <<-EOF &&
|
|
||||||
rebase finished: returning to refs/heads/reflog-apply
|
|
||||||
rebase: Z
|
|
||||||
rebase: checkout Y
|
|
||||||
$old_head_reflog
|
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect actual &&
|
test_cmp expect actual &&
|
||||||
|
|
||||||
git log -g --format=%gs -2 reflog-apply >actual &&
|
# check there is only one new entry in the branch reflog
|
||||||
cat >expect <<-EOF &&
|
test_cmp_rev conflicts@{1} Q
|
||||||
rebase finished: refs/heads/reflog-apply onto $(git rev-parse Y)
|
'
|
||||||
branch: Created from start
|
|
||||||
|
test_expect_success "rebase $mode fast-forward reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
|
||||||
|
git checkout fast-forward &&
|
||||||
|
test_when_finished "git reset --hard X" &&
|
||||||
|
|
||||||
|
(
|
||||||
|
if test -n "$reflog_action"
|
||||||
|
then
|
||||||
|
GIT_REFLOG_ACTION="$reflog_action" &&
|
||||||
|
export GIT_REFLOG_ACTION
|
||||||
|
fi &&
|
||||||
|
git rebase $mode main
|
||||||
|
) &&
|
||||||
|
|
||||||
|
git log -g --format=%gs -2 >actual &&
|
||||||
|
write_reflog_expect <<-EOF &&
|
||||||
|
${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward
|
||||||
|
${reflog_action:-rebase} (start): checkout main
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
git log -g --format=%gs -1 fast-forward >actual &&
|
||||||
|
write_reflog_expect <<-EOF &&
|
||||||
|
${reflog_action:-rebase} (finish): refs/heads/fast-forward onto $(git rev-parse main)
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
# check there is only one new entry in the branch reflog
|
||||||
|
test_cmp_rev fast-forward@{1} X
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "rebase $mode --skip reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
|
||||||
|
git checkout conflicts &&
|
||||||
|
test_when_finished "git reset --hard Q" &&
|
||||||
|
|
||||||
|
(
|
||||||
|
if test -n "$reflog_action"
|
||||||
|
then
|
||||||
|
GIT_REFLOG_ACTION="$reflog_action" &&
|
||||||
|
export GIT_REFLOG_ACTION
|
||||||
|
fi &&
|
||||||
|
test_must_fail git rebase $mode main &&
|
||||||
|
git rebase --skip
|
||||||
|
) &&
|
||||||
|
|
||||||
|
git log -g --format=%gs -4 >actual &&
|
||||||
|
write_reflog_expect <<-EOF &&
|
||||||
|
${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
|
||||||
|
${reflog_action:-rebase} (pick): Q
|
||||||
|
${reflog_action:-rebase} (pick): P
|
||||||
|
${reflog_action:-rebase} (start): checkout main
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success "rebase $mode --abort reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
|
||||||
|
git checkout conflicts &&
|
||||||
|
test_when_finished "git reset --hard Q" &&
|
||||||
|
|
||||||
|
git log -g -1 conflicts >branch-expect &&
|
||||||
|
(
|
||||||
|
if test -n "$reflog_action"
|
||||||
|
then
|
||||||
|
GIT_REFLOG_ACTION="$reflog_action" &&
|
||||||
|
export GIT_REFLOG_ACTION
|
||||||
|
fi &&
|
||||||
|
test_must_fail git rebase $mode main &&
|
||||||
|
git rebase --abort
|
||||||
|
) &&
|
||||||
|
|
||||||
|
git log -g --format=%gs -3 >actual &&
|
||||||
|
write_reflog_expect <<-EOF &&
|
||||||
|
${reflog_action:-rebase} (abort): returning to refs/heads/conflicts
|
||||||
|
${reflog_action:-rebase} (pick): P
|
||||||
|
${reflog_action:-rebase} (start): checkout main
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
# check branch reflog is unchanged
|
||||||
|
git log -g -1 conflicts >branch-actual &&
|
||||||
|
test_cmp branch-expect branch-actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "rebase $mode --abort detached HEAD reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" '
|
||||||
|
git checkout Q &&
|
||||||
|
test_when_finished "git reset --hard Q" &&
|
||||||
|
|
||||||
|
(
|
||||||
|
if test -n "$reflog_action"
|
||||||
|
then
|
||||||
|
GIT_REFLOG_ACTION="$reflog_action" &&
|
||||||
|
export GIT_REFLOG_ACTION
|
||||||
|
fi &&
|
||||||
|
test_must_fail git rebase $mode main &&
|
||||||
|
git rebase --abort
|
||||||
|
) &&
|
||||||
|
|
||||||
|
git log -g --format=%gs -3 >actual &&
|
||||||
|
write_reflog_expect <<-EOF &&
|
||||||
|
${reflog_action:-rebase} (abort): returning to $(git rev-parse Q)
|
||||||
|
${reflog_action:-rebase} (pick): P
|
||||||
|
${reflog_action:-rebase} (start): checkout main
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
test_reflog --merge
|
||||||
|
test_reflog --merge my-reflog-action
|
||||||
|
test_reflog --apply
|
||||||
|
test_reflog --apply my-reflog-action
|
||||||
|
|
||||||
test_expect_success 'rebase -i onto unrelated history' '
|
test_expect_success 'rebase -i onto unrelated history' '
|
||||||
git init unrelated &&
|
git init unrelated &&
|
||||||
|
Reference in New Issue
Block a user