summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Alban Gruin <alban.gruin@gmail.com>2018-08-28 14:10:36 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-08-29 13:38:18 -0700
commitb97e187364990fb8410355ff8b4365d0e37bbbbe (patch)
tree73e0346e20435cb289e56cf2c59e269339c74b43 /builtin
parentt3404: todo list with commented-out commands only aborts (diff)
downloadtgif-b97e187364990fb8410355ff8b4365d0e37bbbbe.tar.xz
rebase -i: rewrite complete_action() in C
This rewrites complete_action() from shell to C. A new mode is added to rebase--helper (`--complete-action`), as well as a new flag (`--autosquash`). Finally, complete_action() is stripped from git-rebase--interactive.sh. The original complete_action() would return the code 2 when the todo list contained no actions. This was a special case for rebase -i and -p; git-rebase.sh would then apply the autostash, delete the state directory, and die with the message "Nothing to do". This cleanup is rewritten in C instead of returning 2. As rebase -i no longer returns 2, the comment describing this behaviour in git-rebase.sh is updated to reflect this change. The message "Nothing to do" is now printed with error(), and so becomes "error: nothing to do". Some tests in t3404 check this value, so they are updated to fit this change. The first check might seem useless as we write "noop" to the todo list if it is empty. Actually, the todo list might contain commented commands (ie. empty commits). In this case, complete_action() won’t write "noop", and will abort without starting the editor. Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/rebase--helper.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index bed3dd2b95..01b3333958 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -13,13 +13,13 @@ static const char * const builtin_rebase_helper_usage[] = {
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
{
struct replay_opts opts = REPLAY_OPTS_INIT;
- unsigned flags = 0, keep_empty = 0, rebase_merges = 0;
+ unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0;
int abbreviate_commands = 0, rebase_cousins = -1;
enum {
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
ADD_EXEC, APPEND_TODO_HELP, EDIT_TODO, PREPARE_BRANCH,
- CHECKOUT_ONTO
+ CHECKOUT_ONTO, COMPLETE_ACTION
} command = 0;
struct option options[] = {
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -29,6 +29,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "rebase-merges", &rebase_merges, N_("rebase merge commits")),
OPT_BOOL(0, "rebase-cousins", &rebase_cousins,
N_("keep original branch points of cousins")),
+ OPT_BOOL(0, "autosquash", &autosquash,
+ N_("move commits that begin with squash!/fixup!")),
OPT__VERBOSE(&opts.verbose, N_("be verbose")),
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
CONTINUE),
@@ -57,6 +59,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
N_("prepare the branch to be rebased"), PREPARE_BRANCH),
OPT_CMDMODE(0, "checkout-onto", &command,
N_("checkout a commit"), CHECKOUT_ONTO),
+ OPT_CMDMODE(0, "complete-action", &command,
+ N_("complete the action"), COMPLETE_ACTION),
OPT_END()
};
@@ -110,5 +114,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
return !!prepare_branch_to_be_rebased(&opts, argv[1]);
if (command == CHECKOUT_ONTO && argc == 4)
return !!checkout_onto(&opts, argv[1], argv[2], argv[3]);
+ if (command == COMPLETE_ACTION && argc == 6)
+ return !!complete_action(&opts, flags, argv[1], argv[2], argv[3],
+ argv[4], argv[5], autosquash);
+
usage_with_options(builtin_rebase_helper_usage, options);
}