]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pull: display default warning only when non-ff
authorFelipe Contreras <felipe.contreras@gmail.com>
Sat, 12 Dec 2020 16:52:08 +0000 (10:52 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Dec 2020 01:39:42 +0000 (17:39 -0800)
There's no need to display the annoying warning on every pull... only
the ones that are not fast-forward.

The current warning tests still pass, but not because of the arguments
or the configuration, but because they are all fast-forward.

We need to test non-fast-forward situations now.

Suggestions-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pull.c
t/t7601-merge-pull-config.sh

index 1b87ea95eb911e9b6b249c78cf3ee7f0755c755d..e8927fc2ffe3398de10b2a695f5b6346ac5a540c 100644 (file)
@@ -949,6 +949,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        struct object_id rebase_fork_point;
        int autostash;
        int rebase_unspecified = 0;
+       int can_ff;
 
        if (!getenv("GIT_REFLOG_ACTION"))
                set_reflog_message(argc, argv);
@@ -1044,7 +1045,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        if (opt_rebase && merge_heads.nr > 1)
                die(_("Cannot rebase onto multiple branches."));
 
-       if (rebase_unspecified && !opt_ff) {
+       can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
+
+       if (rebase_unspecified && !opt_ff && !can_ff) {
                if (opt_verbosity >= 0)
                        show_advice_pull_non_ff();
        }
@@ -1063,7 +1066,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                    submodule_touches_in_range(the_repository, &upstream, &curr_head))
                        die(_("cannot rebase with locally recorded submodule modifications"));
                if (!autostash) {
-                       if (get_can_ff(&orig_head, &merge_heads.oid[0])) {
+                       if (can_ff) {
                                /* we can fast-forward this without invoking rebase */
                                opt_ff = "--ff-only";
                                ran_ff = 1;
index 6774e9d86fa04c901b3833127e72f63a60028236..52e8ccc933ad1269d62fc91348700558dc9b95ef 100755 (executable)
@@ -29,11 +29,8 @@ test_expect_success 'setup' '
 
 test_expect_success 'pull.rebase not set' '
        git reset --hard c0 &&
-       git -c color.advice=always pull . c1 2>err &&
-       test_decode_color <err >decoded &&
-       test_i18ngrep "<YELLOW>hint: " decoded &&
-       test_i18ngrep "Pulling without specifying how to reconcile" decoded
-
+       git pull . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
 '
 
 test_expect_success 'pull.rebase not set and pull.ff=true' '
@@ -87,6 +84,65 @@ test_expect_success 'pull.rebase not set and --ff-only given' '
        test_i18ngrep ! "Pulling without specifying how to reconcile" err
 '
 
+test_expect_success 'pull.rebase not set (not-fast-forward)' '
+       git reset --hard c2 &&
+       git -c color.advice=always pull . c1 2>err &&
+       test_decode_color <err >decoded &&
+       test_i18ngrep "<YELLOW>hint: " decoded &&
+       test_i18ngrep "Pulling without specifying how to reconcile" decoded
+'
+
+test_expect_success 'pull.rebase not set and pull.ff=true (not-fast-forward)' '
+       git reset --hard c2 &&
+       test_config pull.ff true &&
+       git pull . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
+test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' '
+       git reset --hard c2 &&
+       test_config pull.ff false &&
+       git pull . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
+test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' '
+       git reset --hard c2 &&
+       test_config pull.ff only &&
+       test_must_fail git pull . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
+test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' '
+       git reset --hard c2 &&
+       git pull --rebase . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
+test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward)' '
+       git reset --hard c2 &&
+       git pull --no-rebase . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
+test_expect_success 'pull.rebase not set and --ff given (not-fast-forward)' '
+       git reset --hard c2 &&
+       git pull --ff . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
+test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' '
+       git reset --hard c2 &&
+       git pull --no-ff . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
+test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' '
+       git reset --hard c2 &&
+       test_must_fail git pull --ff-only . c1 2>err &&
+       test_i18ngrep ! "Pulling without specifying how to reconcile" err
+'
+
 test_expect_success 'merge c1 with c2' '
        git reset --hard c1 &&
        test -f c0.c &&