pull: make --rebase and --no-rebase override pull.ff=only

Fix the last few precedence tests failing in t7601 by now implementing the logic to have --[no-]rebase override a pull.ff=only config setting. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jul 22, 2021 at 05:04 UTC adc27d6a9374d012b091bc348c20f5bfdbee52d1
2 files changed +17 -3
builtin/pull.c
+15 -1
@@ -966,8 +966,22 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
966
967 parse_repo_refspecs(argc, argv, &repo, &refspecs);
968
969 - if (!opt_ff)
969 + if (!opt_ff) {
970 opt_ff = xstrdup_or_null(config_get_ff());
971 + /*
972 + * A subtle point: opt_ff was set on the line above via
973 + * reading from config. opt_rebase, in contrast, is set
974 + * before this point via command line options. The setting
975 + * of opt_rebase via reading from config (using
976 + * config_get_rebase()) does not happen until later. We
977 + * are relying on the next if-condition happening before
978 + * the config_get_rebase() call so that an explicit
979 + * "--rebase" can override a config setting of
980 + * pull.ff=only.
981 + */
982 + if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only"))
983 + opt_ff = "--ff";
984 + }
985
986 if (opt_rebase < 0)
987 opt_rebase = config_get_rebase(&rebase_unspecified);
t/t7601-merge-pull-config.sh
+2 -2
@@ -260,11 +260,11 @@ test_expect_success '--ff-only takes precedence over pull.rebase=false' '
260 test_attempts_fast_forward -c pull.rebase=false pull --ff-only
261 '
262
263 -test_expect_failure '--no-rebase takes precedence over pull.ff=only' '
263 +test_expect_success '--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_failure '--rebase takes precedence over pull.ff=only' '
267 +test_expect_success '--rebase takes precedence over pull.ff=only' '
268 test_does_rebase -c pull.ff=only pull --rebase
269 '
270