]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pull: should be noop when already-up-to-date
authorErwin Villejo <erwin.villejo@gmail.com>
Wed, 17 Nov 2021 07:55:50 +0000 (07:55 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Nov 2021 22:38:53 +0000 (14:38 -0800)
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>
builtin/pull.c
t/t7601-merge-pull-config.sh

index 54286b544f9d21d50d62c3b96b378ac9c50bb0d3..6ff2a8196e08d9796a237e6bd13f0475d5e4e115 100644 (file)
@@ -984,6 +984,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        struct object_id rebase_fork_point;
        int rebase_unspecified = 0;
        int can_ff;
+       int divergent;
 
        if (!getenv("GIT_REFLOG_ACTION"))
                set_reflog_message(argc, argv);
@@ -1098,15 +1099,16 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        }
 
        can_ff = get_can_ff(&orig_head, &merge_heads);
+       divergent = !can_ff && !already_up_to_date(&orig_head, &merge_heads);
 
        /* ff-only takes precedence over rebase */
        if (opt_ff && !strcmp(opt_ff, "--ff-only")) {
-               if (!can_ff && !already_up_to_date(&orig_head, &merge_heads))
+               if (divergent)
                        die_ff_impossible();
                opt_rebase = REBASE_FALSE;
        }
        /* If no action specified and we can't fast forward, then warn. */
-       if (!opt_ff && rebase_unspecified && !can_ff) {
+       if (!opt_ff && rebase_unspecified && divergent) {
                show_advice_pull_non_ff();
                die(_("Need to specify how to reconcile divergent branches."));
        }
index 6275641b9c2459e69ec201189d9e202fc8f937fe..bd238d89b0cb07ed6a92707dcfd80ac277b75524 100755 (executable)
@@ -387,6 +387,12 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
        test_must_fail git pull . c3
 '
 
+test_expect_success 'already-up-to-date pull succeeds with unspecified pull.ff' '
+       git reset --hard c1 &&
+       git pull . c0 &&
+       test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
+'
+
 test_expect_success 'already-up-to-date pull succeeds with "only" in pull.ff' '
        git reset --hard c1 &&
        test_config pull.ff only &&