@@ -286,6 +286,11 @@ void NORETURN die_conclude_merge(void)
die(_("Exiting because of unfinished merge."));
}
+void NORETURN die_ff_impossible(void)
+{
+ die(_("Not possible to fast-forward, aborting."));
+}
+
void advise_on_updating_sparse_paths(struct string_list *pathspec_list)
{
struct string_list_item *item;
@@ -95,6 +95,7 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...);
int error_resolve_conflict(const char *me);
void NORETURN die_resolve_conflict(const char *me);
void NORETURN die_conclude_merge(void);
+void NORETURN die_ff_impossible(void);
void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
void detach_advice(const char *new_name);
@@ -1620,7 +1620,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
}
if (fast_forward == FF_ONLY)
- die(_("Not possible to fast-forward, aborting."));
+ die_ff_impossible();
if (autostash)
create_autostash(the_repository,
@@ -1070,9 +1070,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
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();
+ if (!can_ff) {
+ if (opt_ff) {
+ if (!strcmp(opt_ff, "--ff-only"))
+ die_ff_impossible();
+ } else {
+ if (rebase_unspecified && opt_verbosity >= 0)
+ show_advice_pull_non_ff();
+ }
}
if (opt_rebase) {
@@ -250,6 +250,30 @@ test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
test_must_fail git pull . c3
'
+test_expect_success 'pull prevents non-fast-forward with pull.ff=only and pull.rebase=true' '
+ git reset --hard c1 &&
+ test_config pull.ff only &&
+ test_config pull.rebase true &&
+ test_must_fail git pull . c3
+'
+
+test_expect_success 'pull prevents non-fast-forward with pull.ff=only and pull.rebase=false' '
+ git reset --hard c1 &&
+ test_config pull.ff only &&
+ test_config pull.rebase false &&
+ test_must_fail git pull . c3
+'
+
+test_expect_success 'pull prevents non-fast-forward with --rebase --ff-only' '
+ git reset --hard c1 &&
+ test_must_fail git pull --rebase --ff-only . c3
+'
+
+test_expect_success 'pull prevents non-fast-forward with --no-rebase --ff-only' '
+ git reset --hard c1 &&
+ test_must_fail git pull --no-rebase --ff-only . c3
+'
+
test_expect_success 'merge c1 with c2 (ours in pull.twohead)' '
git reset --hard c1 &&
git config pull.twohead ours &&