Skip to content

Commit 81dbd76

Browse files
pyokagangitster
authored andcommitted
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 <[email protected]> Helped-by: Duy Nguyen <[email protected]> Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1678b81 commit 81dbd76

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

builtin/pull.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int opt_verbosity;
7272
static char *opt_progress;
7373

7474
/* Options passed to git-merge or git-rebase */
75-
static enum rebase_type opt_rebase;
75+
static enum rebase_type opt_rebase = -1;
7676
static char *opt_diffstat;
7777
static char *opt_log;
7878
static char *opt_squash;
@@ -265,6 +265,36 @@ static const char *config_get_ff(void)
265265
die(_("Invalid value for pull.ff: %s"), value);
266266
}
267267

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+
268298
/**
269299
* Appends merge candidates from FETCH_HEAD that are not marked not-for-merge
270300
* into merge_heads.
@@ -707,6 +737,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
707737
if (!opt_ff)
708738
opt_ff = xstrdup_or_null(config_get_ff());
709739

740+
if (opt_rebase < 0)
741+
opt_rebase = config_get_rebase();
742+
710743
git_config(git_default_config, NULL);
711744

712745
if (read_cache_unmerged())

0 commit comments

Comments
 (0)