builtin rebase: support --force-rebase
In this commit, we add support to `--force-rebase` option. The equivalent part of the shell script found in `git-legacy-rebase.sh` is converted as faithfully as possible to C. The --force-rebase option ensures that the rebase does not simply fast-forward even if it could. 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 14:27 UTC
1ed9c14ff25ca567c8416cad0980ea1b595e5723
1 file changed
+21
-1
builtin/rebase.c
+21
-1
@@ -86,6 +86,7 @@ struct rebase_options {
86
REBASE_NO_QUIET = 1<<0,
87
REBASE_VERBOSE = 1<<1,
88
REBASE_DIFFSTAT = 1<<2,
89
+ REBASE_FORCE = 1<<3,
90
} flags;
91
struct strbuf git_am_opt;
92
};
@@ -181,6 +182,8 @@ static int run_specific_rebase(struct rebase_options *opts)
182
opts->flags & REBASE_VERBOSE ? "t" : "");
183
add_var(&script_snippet, "diffstat",
184
opts->flags & REBASE_DIFFSTAT ? "t" : "");
185
+ add_var(&script_snippet, "force_rebase",
186
+ opts->flags & REBASE_FORCE ? "t" : "");
187
188
switch (opts->type) {
189
case REBASE_AM:
@@ -409,6 +412,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
412
{OPTION_NEGBIT, 'n', "no-stat", &options.flags, NULL,
413
N_("do not show diffstat of what changed upstream"),
414
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
415
+ OPT_BIT('f', "force-rebase", &options.flags,
416
+ N_("cherry-pick all commits, even if unchanged"),
417
+ REBASE_FORCE),
418
+ OPT_BIT(0, "no-ff", &options.flags,
419
+ N_("cherry-pick all commits, even if unchanged"),
420
+ REBASE_FORCE),
421
OPT_END(),
422
};
423
@@ -551,7 +560,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
560
!oidcmp(&options.upstream->object.oid, &options.onto->object.oid)) {
561
int flag;
562
554
- if (!(options.flags & REBASE_NO_QUIET))
563
+ if (!(options.flags & REBASE_FORCE)) {
564
+ if (!(options.flags & REBASE_NO_QUIET))
565
+ ; /* be quiet */
566
+ else if (!strcmp(branch_name, "HEAD") &&
567
+ resolve_ref_unsafe("HEAD", 0, NULL, &flag))
568
+ puts(_("HEAD is up to date."));
569
+ else
570
+ printf(_("Current branch %s is up to date.\n"),
571
+ branch_name);
572
+ ret = !!finish_rebase(&options);
573
+ goto cleanup;
574
+ } else if (!(options.flags & REBASE_NO_QUIET))
575
; /* be quiet */
576
else if (!strcmp(branch_name, "HEAD") &&
577
resolve_ref_unsafe("HEAD", 0, NULL, &flag))