pull: support pull.ff config

Since b814da8 (pull: add pull.ff configuration, 2014-01-15), git-pull.sh would lookup the configuration value of "pull.ff", and set the flag "--ff" if its value is "true", "--no-ff" if its value is "false" and "--ff-only" if its value is "only". Re-implement this behavior. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jun 18, 2015 at 18:54 UTC a9de98975479ef7d42986db63c16251c1f87ebcb
1 file changed +29
builtin/pull.c
+29
@@ -166,6 +166,32 @@ static void argv_push_force(struct argv_array *arr)
166 argv_array_push(arr, "-f");
167 }
168
169 +/**
170 + * If pull.ff is unset, returns NULL. If pull.ff is "true", returns "--ff". If
171 + * pull.ff is "false", returns "--no-ff". If pull.ff is "only", returns
172 + * "--ff-only". Otherwise, if pull.ff is set to an invalid value, die with an
173 + * error.
174 + */
175 +static const char *config_get_ff(void)
176 +{
177 + const char *value;
178 +
179 + if (git_config_get_value("pull.ff", &value))
180 + return NULL;
181 +
182 + switch (git_config_maybe_bool("pull.ff", value)) {
183 + case 0:
184 + return "--no-ff";
185 + case 1:
186 + return "--ff";
187 + }
188 +
189 + if (!strcmp(value, "only"))
190 + return "--ff-only";
191 +
192 + die(_("Invalid value for pull.ff: %s"), value);
193 +}
194 +
195 /**
196 * Appends merge candidates from FETCH_HEAD that are not marked not-for-merge
197 * into merge_heads.
@@ -397,6 +423,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
423
424 parse_repo_refspecs(argc, argv, &repo, &refspecs);
425
426 + if (!opt_ff)
427 + opt_ff = xstrdup_or_null(config_get_ff());
428 +
429 if (run_fetch(repo, refspecs))
430 return 1;
431