pull: abort if --ff-only is given and fast-forwarding is impossible
The warning about pulling without specifying how to reconcile divergent branches says that after setting pull.rebase to true, --ff-only can still be passed on the command line to require a fast-forward. Make that actually work. Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> [en: updated tests; note 3 fixes and 1 new failure] Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alex Henrie committed
Jul 21, 2021 at 01:42 UTC
3d5fc24daefbdf56bc36a491aed0b7990fa0c62f
5 files changed
+20
-9
advice.c
+5
@@ -286,6 +286,11 @@ void NORETURN die_conclude_merge(void)
286
die(_("Exiting because of unfinished merge."));
287
}
288
289
+void NORETURN die_ff_impossible(void)
290
+{
291
+ die(_("Not possible to fast-forward, aborting."));
292
+}
293
+
294
void advise_on_updating_sparse_paths(struct string_list *pathspec_list)
295
{
296
struct string_list_item *item;
advice.h
+1
@@ -95,6 +95,7 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...);
95
int error_resolve_conflict(const char *me);
96
void NORETURN die_resolve_conflict(const char *me);
97
void NORETURN die_conclude_merge(void);
98
+void NORETURN die_ff_impossible(void);
99
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
100
void detach_advice(const char *new_name);
101
builtin/merge.c
+1
-1
@@ -1620,7 +1620,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1620
}
1621
1622
if (fast_forward == FF_ONLY)
1623
- die(_("Not possible to fast-forward, aborting."));
1623
+ die_ff_impossible();
1624
1625
if (autostash)
1626
create_autostash(the_repository,
builtin/pull.c
+8
-3
@@ -1046,9 +1046,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1046
1047
can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
1048
1049
- if (rebase_unspecified && !opt_ff && !can_ff) {
1050
- if (opt_verbosity >= 0)
1051
- show_advice_pull_non_ff();
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
+ }
1057
}
1058
1059
if (opt_rebase) {
t/t7601-merge-pull-config.sh
+5
-5
@@ -209,11 +209,11 @@ test_attempts_fast_forward () {
209
# Group 1: Interaction of --ff-only with --[no-]rebase
210
# (And related interaction of pull.ff=only with pull.rebase)
211
#
212
-test_expect_failure '--ff-only overrides --rebase' '
212
+test_expect_success '--ff-only overrides --rebase' '
213
test_attempts_fast_forward pull --rebase --ff-only
214
'
215
216
-test_expect_failure '--ff-only overrides --rebase even if first' '
216
+test_expect_success '--ff-only overrides --rebase even if first' '
217
test_attempts_fast_forward pull --ff-only --rebase
218
'
219
@@ -221,7 +221,7 @@ test_expect_success '--ff-only overrides --no-rebase' '
221
test_attempts_fast_forward pull --ff-only --no-rebase
222
'
223
224
-test_expect_failure 'pull.ff=only overrides pull.rebase=true' '
224
+test_expect_success 'pull.ff=only overrides pull.rebase=true' '
225
test_attempts_fast_forward -c pull.ff=only -c pull.rebase=true pull
226
'
227
@@ -252,7 +252,7 @@ test_expect_success 'pull.rebase=true overrides pull.ff=true' '
252
'
253
254
# Group 3: command line flags take precedence over config
255
-test_expect_failure '--ff-only takes precedence over pull.rebase=true' '
255
+test_expect_success '--ff-only takes precedence over pull.rebase=true' '
256
test_attempts_fast_forward -c pull.rebase=true pull --ff-only
257
'
258
@@ -264,7 +264,7 @@ test_expect_failure '--no-rebase takes precedence over pull.ff=only' '
264
test_falls_back_to_full_merge -c pull.ff=only pull --no-rebase
265
'
266
267
-test_expect_success '--rebase takes precedence over pull.ff=only' '
267
+test_expect_failure '--rebase takes precedence over pull.ff=only' '
268
test_does_rebase -c pull.ff=only pull --rebase
269
'
270