Skip to content

Commit 1ed9c14

Browse files
prertikgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a48a61 commit 1ed9c14

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

builtin/rebase.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct rebase_options {
8686
REBASE_NO_QUIET = 1<<0,
8787
REBASE_VERBOSE = 1<<1,
8888
REBASE_DIFFSTAT = 1<<2,
89+
REBASE_FORCE = 1<<3,
8990
} flags;
9091
struct strbuf git_am_opt;
9192
};
@@ -181,6 +182,8 @@ static int run_specific_rebase(struct rebase_options *opts)
181182
opts->flags & REBASE_VERBOSE ? "t" : "");
182183
add_var(&script_snippet, "diffstat",
183184
opts->flags & REBASE_DIFFSTAT ? "t" : "");
185+
add_var(&script_snippet, "force_rebase",
186+
opts->flags & REBASE_FORCE ? "t" : "");
184187

185188
switch (opts->type) {
186189
case REBASE_AM:
@@ -409,6 +412,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
409412
{OPTION_NEGBIT, 'n', "no-stat", &options.flags, NULL,
410413
N_("do not show diffstat of what changed upstream"),
411414
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),
412421
OPT_END(),
413422
};
414423

@@ -551,7 +560,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
551560
!oidcmp(&options.upstream->object.oid, &options.onto->object.oid)) {
552561
int flag;
553562

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))
555575
; /* be quiet */
556576
else if (!strcmp(branch_name, "HEAD") &&
557577
resolve_ref_unsafe("HEAD", 0, NULL, &flag))

0 commit comments

Comments
 (0)