environment: move "branch.autoSetupMerge" into `struct repo_config_values`

The config value `branch.autoSetupMerge` is parsed in `git_default_branch_config()` and stored in the global variable `git_branch_track`. This global variable can be overwritten by another repository when multiple Git repos run in the the same process. Move this value into `struct repo_config_values` in the_repository to retain current behaviours and move towards libifying Git. Since the variable is no longer a global variable, it has been renamed to `branch_track` in the struct `repo_config_values`. Suggested-by: Phillip Wood <phillip.wood123@gmail.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Olamide Caleb Bello committed Feb 16, 2026 at 17:38 UTC cf50830ce1d1b95a44f9d095ff868e7df1495863
7 files changed +19 -11
branch.h
-2
@@ -15,8 +15,6 @@ enum branch_track {
15 BRANCH_TRACK_SIMPLE,
16 };
17
18 -extern enum branch_track git_branch_track;
19 -
18 /* Functions for acting on the information about branches. */
19
20 /**
builtin/branch.c
+2 -1
@@ -724,6 +724,7 @@ int cmd_branch(int argc,
724 static struct ref_sorting *sorting;
725 struct string_list sorting_options = STRING_LIST_INIT_DUP;
726 struct ref_format format = REF_FORMAT_INIT;
727 + struct repo_config_values *cfg = repo_config_values(the_repository);
728 int ret;
729
730 struct option options[] = {
@@ -795,7 +796,7 @@ int cmd_branch(int argc,
796 if (!sorting_options.nr)
797 string_list_append(&sorting_options, "refname");
798
798 - track = git_branch_track;
799 + track = cfg->branch_track;
800
801 head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
802 0, &head_oid, NULL);
builtin/checkout.c
+2 -1
@@ -1588,6 +1588,7 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts,
1588 static int checkout_branch(struct checkout_opts *opts,
1589 struct branch_info *new_branch_info)
1590 {
1591 + struct repo_config_values *cfg = repo_config_values(the_repository);
1592 int noop_switch = (!new_branch_info->name &&
1593 !opts->new_branch &&
1594 !opts->force_detach);
@@ -1631,7 +1632,7 @@ static int checkout_branch(struct checkout_opts *opts,
1632 if (opts->track != BRANCH_TRACK_UNSPECIFIED)
1633 die(_("'%s' cannot be used with '%s'"), "--detach", "-t");
1634 } else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
1634 - opts->track = git_branch_track;
1635 + opts->track = cfg->branch_track;
1636
1637 if (new_branch_info->name && !new_branch_info->commit)
1638 die(_("Cannot switch branch to a non-commit '%s'"),
builtin/push.c
+2 -1
@@ -151,6 +151,7 @@ static NORETURN void die_push_simple(struct branch *branch,
151 const char *advice_pushdefault_maybe = "";
152 const char *advice_automergesimple_maybe = "";
153 const char *short_upstream = branch->merge[0]->src;
154 + struct repo_config_values *cfg = repo_config_values(the_repository);
155
156 skip_prefix(short_upstream, "refs/heads/", &short_upstream);
157
@@ -162,7 +163,7 @@ static NORETURN void die_push_simple(struct branch *branch,
163 advice_pushdefault_maybe = _("\n"
164 "To choose either option permanently, "
165 "see push.default in 'git help config'.\n");
165 - if (git_branch_track != BRANCH_TRACK_SIMPLE)
166 + if (cfg->branch_track != BRANCH_TRACK_SIMPLE)
167 advice_automergesimple_maybe = _("\n"
168 "To avoid automatically configuring "
169 "an upstream branch when its name\n"
builtin/submodule--helper.c
+2 -1
@@ -3126,9 +3126,10 @@ static int module_create_branch(int argc, const char **argv, const char *prefix,
3126 N_("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>"),
3127 NULL
3128 };
3129 + struct repo_config_values *cfg = repo_config_values(the_repository);
3130
3131 repo_config(the_repository, git_default_config, NULL);
3131 - track = git_branch_track;
3132 + track = cfg->branch_track;
3133 argc = parse_options(argc, argv, prefix, options, usage, 0);
3134
3135 if (argc != 3)
environment.c
+7 -5
@@ -66,7 +66,6 @@ enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
66 enum eol core_eol = EOL_UNSET;
67 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
68 char *check_roundtrip_encoding;
69 -enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
69 enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
70 enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
71 #ifndef OBJECT_CREATION_MODE
@@ -607,18 +606,20 @@ static int git_default_i18n_config(const char *var, const char *value)
606
607 static int git_default_branch_config(const char *var, const char *value)
608 {
609 + struct repo_config_values *cfg = repo_config_values(the_repository);
610 +
611 if (!strcmp(var, "branch.autosetupmerge")) {
612 if (value && !strcmp(value, "always")) {
612 - git_branch_track = BRANCH_TRACK_ALWAYS;
613 + cfg->branch_track = BRANCH_TRACK_ALWAYS;
614 return 0;
615 } else if (value && !strcmp(value, "inherit")) {
615 - git_branch_track = BRANCH_TRACK_INHERIT;
616 + cfg->branch_track = BRANCH_TRACK_INHERIT;
617 return 0;
618 } else if (value && !strcmp(value, "simple")) {
618 - git_branch_track = BRANCH_TRACK_SIMPLE;
619 + cfg->branch_track = BRANCH_TRACK_SIMPLE;
620 return 0;
621 }
621 - git_branch_track = git_config_bool(var, value);
622 + cfg->branch_track = git_config_bool(var, value);
623 return 0;
624 }
625 if (!strcmp(var, "branch.autosetuprebase")) {
@@ -761,4 +762,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
762 {
763 cfg->attributes_file = NULL;
764 cfg->apply_sparse_checkout = 0;
765 + cfg->branch_track = BRANCH_TRACK_REMOTE;
766 }
environment.h
+4
@@ -2,6 +2,7 @@
2 #define ENVIRONMENT_H
3
4 #include "repo-settings.h"
5 +#include "branch.h"
6
7 /* Double-check local_repo_env below if you add to this list. */
8 #define GIT_DIR_ENVIRONMENT "GIT_DIR"
@@ -89,6 +90,9 @@ struct repo_config_values {
90 /* section "core" config values */
91 char *attributes_file;
92 int apply_sparse_checkout;
93 +
94 + /* section "branch" config values */
95 + enum branch_track branch_track;
96 };
97
98 struct repo_config_values *repo_config_values(struct repository *repo);