summaryrefslogtreecommitdiff
path: root/builtin/rebase.c
diff options
context:
space:
mode:
authorPratik Karki <predatoramigo@gmail.com>2018-09-04 22:00:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-10-11 05:12:45 (GMT)
commit68e46d78683bf3cbf707fdad9d95f4cd72cc5dd5 (patch)
tree51f30b198faee0e34fffa98337178022d79a6600 /builtin/rebase.c
parent6defce2b02909b8e0fcf1ffeecee743688b97b49 (diff)
downloadgit-68e46d78683bf3cbf707fdad9d95f4cd72cc5dd5.zip
git-68e46d78683bf3cbf707fdad9d95f4cd72cc5dd5.tar.gz
git-68e46d78683bf3cbf707fdad9d95f4cd72cc5dd5.tar.bz2
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>
Diffstat (limited to 'builtin/rebase.c')
-rw-r--r--builtin/rebase.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 07d8dc6..2c73cc8 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -93,6 +93,7 @@ struct rebase_options {
int autosquash;
char *gpg_sign_opt;
int autostash;
+ char *cmd;
};
static int is_interactive(struct rebase_options *opts)
@@ -346,6 +347,7 @@ static int run_specific_rebase(struct rebase_options *opts)
add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : "");
add_var(&script_snippet, "autosquash", opts->autosquash ? "t" : "");
add_var(&script_snippet, "gpg_sign_opt", opts->gpg_sign_opt);
+ add_var(&script_snippet, "cmd", opts->cmd);
switch (opts->type) {
case REBASE_AM:
@@ -619,6 +621,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
const char *gpg_sign = NULL;
int opt_c = -1;
struct string_list whitespace = STRING_LIST_INIT_NODUP;
+ struct string_list exec = STRING_LIST_INIT_NODUP;
struct option builtin_rebase_options[] = {
OPT_STRING(0, "onto", &options.onto_name,
N_("revision"),
@@ -692,6 +695,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
REBASE_AM),
OPT_BOOL(0, "autostash", &options.autostash,
N_("automatically stash/stash pop before and after")),
+ OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
+ N_("add exec lines after each commit of the "
+ "editable list")),
OPT_END(),
};
@@ -916,6 +922,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
}
}
+ if (exec.nr) {
+ int i;
+
+ imply_interactive(&options, "--exec");
+
+ strbuf_reset(&buf);
+ for (i = 0; i < exec.nr; i++)
+ strbuf_addf(&buf, "exec %s\n", exec.items[i].string);
+ options.cmd = xstrdup(buf.buf);
+ }
+
switch (options.type) {
case REBASE_MERGE:
case REBASE_INTERACTIVE:
@@ -1198,5 +1215,6 @@ cleanup:
strbuf_release(&revisions);
free(options.head_name);
free(options.gpg_sign_opt);
+ free(options.cmd);
return ret;
}