summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/rebase--helper.c56
1 files changed, 53 insertions, 3 deletions
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index e1460136f5..acc71a6f99 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -4,6 +4,25 @@
#include "parse-options.h"
#include "sequencer.h"
#include "rebase-interactive.h"
+#include "argv-array.h"
+
+static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto")
+
+static int get_revision_ranges(const char *upstream, const char *onto,
+ const char **head_hash,
+ char **revisions)
+{
+ const char *base_rev = upstream ? upstream : onto;
+ struct object_id orig_head;
+
+ if (get_oid("HEAD", &orig_head))
+ return error(_("no HEAD?"));
+
+ *head_hash = find_unique_abbrev(&orig_head, GIT_MAX_HEXSZ);
+ *revisions = xstrfmt("%s...%s", base_rev, *head_hash);
+
+ return 0;
+}
static const char * const builtin_rebase_helper_usage[] = {
N_("git rebase--helper [<options>]"),
@@ -14,7 +33,9 @@ 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, autosquash = 0;
- int abbreviate_commands = 0, rebase_cousins = -1;
+ int abbreviate_commands = 0, rebase_cousins = -1, ret;
+ const char *head_hash = NULL, *onto = NULL, *restrict_revision = NULL,
+ *squash_onto = NULL, *upstream = NULL;
enum {
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC, EDIT_TODO, PREPARE_BRANCH,
@@ -54,6 +75,13 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
N_("prepare the branch to be rebased"), PREPARE_BRANCH),
OPT_CMDMODE(0, "complete-action", &command,
N_("complete the action"), COMPLETE_ACTION),
+ OPT_STRING(0, "onto", &onto, N_("onto"), N_("onto")),
+ OPT_STRING(0, "restrict-revision", &restrict_revision,
+ N_("restrict-revision"), N_("restrict revision")),
+ OPT_STRING(0, "squash-onto", &squash_onto, N_("squash-onto"),
+ N_("squash onto")),
+ OPT_STRING(0, "upstream", &upstream, N_("upstream"),
+ N_("the upstream commit")),
OPT_END()
};
@@ -81,8 +109,30 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
return !!sequencer_continue(&opts);
if (command == ABORT && argc == 1)
return !!sequencer_remove_state(&opts);
- if (command == MAKE_SCRIPT && argc > 1)
- return !!sequencer_make_script(stdout, argc, argv, flags);
+ if (command == MAKE_SCRIPT && argc == 1) {
+ char *revisions = NULL;
+ struct argv_array make_script_args = ARGV_ARRAY_INIT;
+
+ if (!upstream && squash_onto)
+ write_file(path_squash_onto(), "%s\n", squash_onto);
+
+ ret = get_revision_ranges(upstream, onto, &head_hash, &revisions);
+ if (ret)
+ return ret;
+
+ argv_array_pushl(&make_script_args, "", revisions, NULL);
+ if (restrict_revision)
+ argv_array_push(&make_script_args, restrict_revision);
+
+ ret = sequencer_make_script(stdout,
+ make_script_args.argc, make_script_args.argv,
+ flags);
+
+ free(revisions);
+ argv_array_clear(&make_script_args);
+
+ return !!ret;
+ }
if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
return !!transform_todos(flags);
if (command == CHECK_TODO_LIST && argc == 1)