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 <predatoramigo@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pratik Karki committed
Sep 4, 2018 at 15:00 UTC
68e46d78683bf3cbf707fdad9d95f4cd72cc5dd5
1 file changed
+18
builtin/rebase.c
+18
@@ -93,6 +93,7 @@ struct rebase_options {
93
int autosquash;
94
char *gpg_sign_opt;
95
int autostash;
96
+ char *cmd;
97
};
98
99
static int is_interactive(struct rebase_options *opts)
@@ -346,6 +347,7 @@ static int run_specific_rebase(struct rebase_options *opts)
347
add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : "");
348
add_var(&script_snippet, "autosquash", opts->autosquash ? "t" : "");
349
add_var(&script_snippet, "gpg_sign_opt", opts->gpg_sign_opt);
350
+ add_var(&script_snippet, "cmd", opts->cmd);
351
352
switch (opts->type) {
353
case REBASE_AM:
@@ -619,6 +621,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
621
const char *gpg_sign = NULL;
622
int opt_c = -1;
623
struct string_list whitespace = STRING_LIST_INIT_NODUP;
624
+ struct string_list exec = STRING_LIST_INIT_NODUP;
625
struct option builtin_rebase_options[] = {
626
OPT_STRING(0, "onto", &options.onto_name,
627
N_("revision"),
@@ -692,6 +695,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
695
REBASE_AM),
696
OPT_BOOL(0, "autostash", &options.autostash,
697
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")),
701
OPT_END(),
702
};
703
@@ -916,6 +922,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
922
}
923
}
924
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
+
936
switch (options.type) {
937
case REBASE_MERGE:
938
case REBASE_INTERACTIVE:
@@ -1198,5 +1215,6 @@ cleanup:
1215
strbuf_release(&revisions);
1216
free(options.head_name);
1217
free(options.gpg_sign_opt);
1218
+ free(options.cmd);
1219
return ret;
1220
}