pull: should be noop when already-up-to-date

The already-up-to-date pull bug was fixed for --ff-only but it did not include the case where --ff or --ff-only are not specified. This updates the --ff-only fix to include the case where --ff or --ff-only are not specified in command line flags or config. Signed-off-by: Erwin Villejo <erwin.villejo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erwin Villejo committed Nov 17, 2021 at 07:55 UTC ea1954af771253660cd84dc73b8f2832327c9c02
2 files changed +10 -2
builtin/pull.c
+4 -2
@@ -984,6 +984,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
984 struct object_id rebase_fork_point;
985 int rebase_unspecified = 0;
986 int can_ff;
987 + int divergent;
988
989 if (!getenv("GIT_REFLOG_ACTION"))
990 set_reflog_message(argc, argv);
@@ -1098,15 +1099,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1099 }
1100
1101 can_ff = get_can_ff(&orig_head, &merge_heads);
1102 + divergent = !can_ff && !already_up_to_date(&orig_head, &merge_heads);
1103
1104 /* ff-only takes precedence over rebase */
1105 if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
1104 - if (!can_ff && !already_up_to_date(&orig_head, &merge_heads))
1106 + if (divergent)
1107 die_ff_impossible();
1108 opt_rebase = REBASE_FALSE;
1109 }
1110 /* If no action specified and we can't fast forward, then warn. */
1109 - if (!opt_ff && rebase_unspecified && !can_ff) {
1111 + if (!opt_ff && rebase_unspecified && divergent) {
1112 show_advice_pull_non_ff();
1113 die(_("Need to specify how to reconcile divergent branches."));
1114 }
t/t7601-merge-pull-config.sh
+6
@@ -387,6 +387,12 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
387 test_must_fail git pull . c3
388 '
389
390 +test_expect_success 'already-up-to-date pull succeeds with unspecified pull.ff' '
391 + git reset --hard c1 &&
392 + git pull . c0 &&
393 + test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
394 +'
395 +
396 test_expect_success 'already-up-to-date pull succeeds with "only" in pull.ff' '
397 git reset --hard c1 &&
398 test_config pull.ff only &&