pull: display default warning only when non-ff

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>

Felipe Contreras committed Dec 12, 2020 at 10:52 UTC c525de335e4a3919d49a9126b76d1288f35737be
2 files changed +66 -7
builtin/pull.c
+5 -2
@@ -949,6 +949,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
949 struct object_id rebase_fork_point;
950 int autostash;
951 int rebase_unspecified = 0;
952 + int can_ff;
953
954 if (!getenv("GIT_REFLOG_ACTION"))
955 set_reflog_message(argc, argv);
@@ -1044,7 +1045,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1045 if (opt_rebase && merge_heads.nr > 1)
1046 die(_("Cannot rebase onto multiple branches."));
1047
1047 - if (rebase_unspecified && !opt_ff) {
1048 + can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
1049 +
1050 + if (rebase_unspecified && !opt_ff && !can_ff) {
1051 if (opt_verbosity >= 0)
1052 show_advice_pull_non_ff();
1053 }
@@ -1063,7 +1066,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1066 submodule_touches_in_range(the_repository, &upstream, &curr_head))
1067 die(_("cannot rebase with locally recorded submodule modifications"));
1068 if (!autostash) {
1066 - if (get_can_ff(&orig_head, &merge_heads.oid[0])) {
1069 + if (can_ff) {
1070 /* we can fast-forward this without invoking rebase */
1071 opt_ff = "--ff-only";
1072 ran_ff = 1;
t/t7601-merge-pull-config.sh
+61 -5
@@ -29,11 +29,8 @@ test_expect_success 'setup' '
29
30 test_expect_success 'pull.rebase not set' '
31 git reset --hard c0 &&
32 - git -c color.advice=always pull . c1 2>err &&
33 - test_decode_color <err >decoded &&
34 - test_i18ngrep "<YELLOW>hint: " decoded &&
35 - test_i18ngrep "Pulling without specifying how to reconcile" decoded
36 -
32 + git pull . c1 2>err &&
33 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
34 '
35
36 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' '
84 test_i18ngrep ! "Pulling without specifying how to reconcile" err
85 '
86
87 +test_expect_success 'pull.rebase not set (not-fast-forward)' '
88 + git reset --hard c2 &&
89 + git -c color.advice=always pull . c1 2>err &&
90 + test_decode_color <err >decoded &&
91 + test_i18ngrep "<YELLOW>hint: " decoded &&
92 + test_i18ngrep "Pulling without specifying how to reconcile" decoded
93 +'
94 +
95 +test_expect_success 'pull.rebase not set and pull.ff=true (not-fast-forward)' '
96 + git reset --hard c2 &&
97 + test_config pull.ff true &&
98 + git pull . c1 2>err &&
99 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
100 +'
101 +
102 +test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' '
103 + git reset --hard c2 &&
104 + test_config pull.ff false &&
105 + git pull . c1 2>err &&
106 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
107 +'
108 +
109 +test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' '
110 + git reset --hard c2 &&
111 + test_config pull.ff only &&
112 + test_must_fail git pull . c1 2>err &&
113 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
114 +'
115 +
116 +test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' '
117 + git reset --hard c2 &&
118 + git pull --rebase . c1 2>err &&
119 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
120 +'
121 +
122 +test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward)' '
123 + git reset --hard c2 &&
124 + git pull --no-rebase . c1 2>err &&
125 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
126 +'
127 +
128 +test_expect_success 'pull.rebase not set and --ff given (not-fast-forward)' '
129 + git reset --hard c2 &&
130 + git pull --ff . c1 2>err &&
131 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
132 +'
133 +
134 +test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' '
135 + git reset --hard c2 &&
136 + git pull --no-ff . c1 2>err &&
137 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
138 +'
139 +
140 +test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' '
141 + git reset --hard c2 &&
142 + test_must_fail git pull --ff-only . c1 2>err &&
143 + test_i18ngrep ! "Pulling without specifying how to reconcile" err
144 +'
145 +
146 test_expect_success 'merge c1 with c2' '
147 git reset --hard c1 &&
148 test -f c0.c &&