Skip to content

Commit e4dc25e

Browse files
newrengitster
authored andcommitted
pull: since --ff-only overrides, handle it first
There are both merge and rebase branches in the logic, and previously both had to handle fast-forwarding. Merge handled that implicitly (because git merge handles it directly), while in rebase it was explicit. Given that the --ff-only flag is meant to override any --rebase or --no-rebase, make the code reflect that by handling --ff-only before the merge-vs-rebase logic. It turns out that this also fixes a bug for submodules. Previously, when --ff-only was given, the code would run `merge --ff-only` on the main module, and then run `submodule update --recursive --rebase` on the submodules. With this change, we still run `merge --ff-only` on the main module, but now run `submodule update --recursive --checkout` on the submodules. I believe this better reflects the intent of --ff-only to have it apply to both the main module and the submodules. (Sidenote: It is somewhat interesting that all merges pass `--checkout` to submodule update, even when `--no-ff` is specified, meaning that it will only do fast-forward merges for submodules. This was discussed in commit a6d7eb2 ("pull: optionally rebase submodules (remote submodule changes only)", 2017-06-23). The same limitations apply now as then, so we are not trying to fix this at this time.) Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3d5fc24 commit e4dc25e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/pull.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,15 +1046,15 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10461046

10471047
can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
10481048

1049-
if (!can_ff) {
1050-
if (opt_ff) {
1051-
if (!strcmp(opt_ff, "--ff-only"))
1052-
die_ff_impossible();
1053-
} else {
1054-
if (rebase_unspecified && opt_verbosity >= 0)
1055-
show_advice_pull_non_ff();
1056-
}
1049+
/* ff-only takes precedence over rebase */
1050+
if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
1051+
if (!can_ff)
1052+
die_ff_impossible();
1053+
opt_rebase = REBASE_FALSE;
10571054
}
1055+
/* If no action specified and we can't fast forward, then warn. */
1056+
if (!opt_ff && rebase_unspecified && !can_ff)
1057+
show_advice_pull_non_ff();
10581058

10591059
if (opt_rebase) {
10601060
int ret = 0;

0 commit comments

Comments
 (0)