Skip to content

Commit 68e46d7

Browse files
prertikgitster
authored andcommitted
builtin rebase: support --exec
This commit adds support for the `--exec` option which takes a shell command-line as argument. This argument will be appended as an `exec <cmd>` command after each line in the todo list that creates a commit in the final history. commands. Note: while the shell script version of `git rebase` assigned the empty string to `cmd` by default, we *unset* it here because the code looks nicer and it does not change the behavior. The `--exec` option requires `--interactive` machinery. Signed-off-by: Pratik Karki <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6defce2 commit 68e46d7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

builtin/rebase.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct rebase_options {
9393
int autosquash;
9494
char *gpg_sign_opt;
9595
int autostash;
96+
char *cmd;
9697
};
9798

9899
static int is_interactive(struct rebase_options *opts)
@@ -346,6 +347,7 @@ static int run_specific_rebase(struct rebase_options *opts)
346347
add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : "");
347348
add_var(&script_snippet, "autosquash", opts->autosquash ? "t" : "");
348349
add_var(&script_snippet, "gpg_sign_opt", opts->gpg_sign_opt);
350+
add_var(&script_snippet, "cmd", opts->cmd);
349351

350352
switch (opts->type) {
351353
case REBASE_AM:
@@ -619,6 +621,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
619621
const char *gpg_sign = NULL;
620622
int opt_c = -1;
621623
struct string_list whitespace = STRING_LIST_INIT_NODUP;
624+
struct string_list exec = STRING_LIST_INIT_NODUP;
622625
struct option builtin_rebase_options[] = {
623626
OPT_STRING(0, "onto", &options.onto_name,
624627
N_("revision"),
@@ -692,6 +695,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
692695
REBASE_AM),
693696
OPT_BOOL(0, "autostash", &options.autostash,
694697
N_("automatically stash/stash pop before and after")),
698+
OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
699+
N_("add exec lines after each commit of the "
700+
"editable list")),
695701
OPT_END(),
696702
};
697703

@@ -916,6 +922,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
916922
}
917923
}
918924

925+
if (exec.nr) {
926+
int i;
927+
928+
imply_interactive(&options, "--exec");
929+
930+
strbuf_reset(&buf);
931+
for (i = 0; i < exec.nr; i++)
932+
strbuf_addf(&buf, "exec %s\n", exec.items[i].string);
933+
options.cmd = xstrdup(buf.buf);
934+
}
935+
919936
switch (options.type) {
920937
case REBASE_MERGE:
921938
case REBASE_INTERACTIVE:
@@ -1198,5 +1215,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11981215
strbuf_release(&revisions);
11991216
free(options.head_name);
12001217
free(options.gpg_sign_opt);
1218+
free(options.cmd);
12011219
return ret;
12021220
}

0 commit comments

Comments
 (0)