Skip to content

Commit 3d5fc24

Browse files
alexhenriegitster
authored andcommitted
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>
1 parent 1d25e5b commit 3d5fc24

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

advice.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ void NORETURN die_conclude_merge(void)
286286
die(_("Exiting because of unfinished merge."));
287287
}
288288

289+
void NORETURN die_ff_impossible(void)
290+
{
291+
die(_("Not possible to fast-forward, aborting."));
292+
}
293+
289294
void advise_on_updating_sparse_paths(struct string_list *pathspec_list)
290295
{
291296
struct string_list_item *item;

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...);
9595
int error_resolve_conflict(const char *me);
9696
void NORETURN die_resolve_conflict(const char *me);
9797
void NORETURN die_conclude_merge(void);
98+
void NORETURN die_ff_impossible(void);
9899
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
99100
void detach_advice(const char *new_name);
100101

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
16201620
}
16211621

16221622
if (fast_forward == FF_ONLY)
1623-
die(_("Not possible to fast-forward, aborting."));
1623+
die_ff_impossible();
16241624

16251625
if (autostash)
16261626
create_autostash(the_repository,

builtin/pull.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10461046

10471047
can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]);
10481048

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+
}
10521057
}
10531058

10541059
if (opt_rebase) {

t/t7601-merge-pull-config.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,19 @@ test_attempts_fast_forward () {
209209
# Group 1: Interaction of --ff-only with --[no-]rebase
210210
# (And related interaction of pull.ff=only with pull.rebase)
211211
#
212-
test_expect_failure '--ff-only overrides --rebase' '
212+
test_expect_success '--ff-only overrides --rebase' '
213213
test_attempts_fast_forward pull --rebase --ff-only
214214
'
215215

216-
test_expect_failure '--ff-only overrides --rebase even if first' '
216+
test_expect_success '--ff-only overrides --rebase even if first' '
217217
test_attempts_fast_forward pull --ff-only --rebase
218218
'
219219

220220
test_expect_success '--ff-only overrides --no-rebase' '
221221
test_attempts_fast_forward pull --ff-only --no-rebase
222222
'
223223

224-
test_expect_failure 'pull.ff=only overrides pull.rebase=true' '
224+
test_expect_success 'pull.ff=only overrides pull.rebase=true' '
225225
test_attempts_fast_forward -c pull.ff=only -c pull.rebase=true pull
226226
'
227227

@@ -252,7 +252,7 @@ test_expect_success 'pull.rebase=true overrides pull.ff=true' '
252252
'
253253

254254
# 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' '
256256
test_attempts_fast_forward -c pull.rebase=true pull --ff-only
257257
'
258258

@@ -264,7 +264,7 @@ test_expect_failure '--no-rebase takes precedence over pull.ff=only' '
264264
test_falls_back_to_full_merge -c pull.ff=only pull --no-rebase
265265
'
266266

267-
test_expect_success '--rebase takes precedence over pull.ff=only' '
267+
test_expect_failure '--rebase takes precedence over pull.ff=only' '
268268
test_does_rebase -c pull.ff=only pull --rebase
269269
'
270270

0 commit comments

Comments
 (0)