pull: configure --rebase via branch.<name>.rebase or pull.rebase

Since cd67e4d (Teach 'git pull' about --rebase, 2007-11-28), fetch+rebase could be set by default by defining the config variable branch.<name>.rebase. This setting can be overriden on the command line by --rebase and --no-rebase. Since 6b37dff (pull: introduce a pull.rebase option to enable --rebase, 2011-11-06), git-pull --rebase can also be configured via the pull.rebase configuration option. Re-implement support for these two configuration settings by introducing config_get_rebase() which is called before parse_options() to set the default value of opt_rebase. Helped-by: Stefan Beller <sbeller@google.com> Helped-by: Duy Nguyen <pclouds@gmail.com> 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 81dbd768dbeba4b3d65c485968920347460e309c
1 file changed +34 -1
builtin/pull.c
+34 -1
@@ -72,7 +72,7 @@ static int opt_verbosity;
72 static char *opt_progress;
73
74 /* Options passed to git-merge or git-rebase */
75 -static enum rebase_type opt_rebase;
75 +static enum rebase_type opt_rebase = -1;
76 static char *opt_diffstat;
77 static char *opt_log;
78 static char *opt_squash;
@@ -265,6 +265,36 @@ static const char *config_get_ff(void)
265 die(_("Invalid value for pull.ff: %s"), value);
266 }
267
268 +/**
269 + * Returns the default configured value for --rebase. It first looks for the
270 + * value of "branch.$curr_branch.rebase", where $curr_branch is the current
271 + * branch, and if HEAD is detached or the configuration key does not exist,
272 + * looks for the value of "pull.rebase". If both configuration keys do not
273 + * exist, returns REBASE_FALSE.
274 + */
275 +static enum rebase_type config_get_rebase(void)
276 +{
277 + struct branch *curr_branch = branch_get("HEAD");
278 + const char *value;
279 +
280 + if (curr_branch) {
281 + char *key = xstrfmt("branch.%s.rebase", curr_branch->name);
282 +
283 + if (!git_config_get_value(key, &value)) {
284 + enum rebase_type ret = parse_config_rebase(key, value, 1);
285 + free(key);
286 + return ret;
287 + }
288 +
289 + free(key);
290 + }
291 +
292 + if (!git_config_get_value("pull.rebase", &value))
293 + return parse_config_rebase("pull.rebase", value, 1);
294 +
295 + return REBASE_FALSE;
296 +}
297 +
298 /**
299 * Appends merge candidates from FETCH_HEAD that are not marked not-for-merge
300 * into merge_heads.
@@ -707,6 +737,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
737 if (!opt_ff)
738 opt_ff = xstrdup_or_null(config_get_ff());
739
740 + if (opt_rebase < 0)
741 + opt_rebase = config_get_rebase();
742 +
743 git_config(git_default_config, NULL);
744
745 if (read_cache_unmerged())