]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move "branch.autoSetupMerge" into `struct repo_config_values`
authorOlamide Caleb Bello <belkid98@gmail.com>
Tue, 13 Jan 2026 16:44:02 +0000 (17:44 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Jan 2026 19:14:42 +0000 (11:14 -0800)
The config value `brach.autoSetupMerge` is parsed in
`git_default_branch_config()` and stored in the global variable
`git_branch_track`. This global variable can cause unexpected behaviours
when multiple Git repos run in the the same process.

Move this value into `struct repo_config_values` which holds all values
parsed by `git_default_config()` and can be accessed per
repo via `git_default_config()`. This would retain the same
behaviours while achieving repository scoped access.

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>
branch.h
builtin/branch.c
builtin/checkout.c
builtin/push.c
builtin/submodule--helper.c
environment.c
environment.h
repository.c

index ec2f35fda449aa365c424aad6ce05907b57d52a5..3dc6e2a0ffe6359eecd9ca169ff4483e8880a256 100644 (file)
--- a/branch.h
+++ b/branch.h
@@ -15,8 +15,6 @@ enum branch_track {
        BRANCH_TRACK_SIMPLE,
 };
 
-extern enum branch_track git_branch_track;
-
 /* Functions for acting on the information about branches. */
 
 /**
index c577b5d20f296911abe04be6d935cce7221b0282..d75114b41c5df70d8d971124f6ce82cce8eb7ce9 100644 (file)
@@ -795,7 +795,7 @@ int cmd_branch(int argc,
        if (!sorting_options.nr)
                string_list_append(&sorting_options, "refname");
 
-       track = git_branch_track;
+       track = the_repository->config_values.git_branch_track;
 
        head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
                                   0, &head_oid, NULL);
index 66b69df6e67234a5c67525abd4c432490ba561e9..adf606c493129b0950351e1d0aca52ef6fe1a62e 100644 (file)
@@ -1631,7 +1631,7 @@ static int checkout_branch(struct checkout_opts *opts,
                if (opts->track != BRANCH_TRACK_UNSPECIFIED)
                        die(_("'%s' cannot be used with '%s'"), "--detach", "-t");
        } else if (opts->track == BRANCH_TRACK_UNSPECIFIED)
-               opts->track = git_branch_track;
+               opts->track = the_repository->config_values.git_branch_track;
 
        if (new_branch_info->name && !new_branch_info->commit)
                die(_("Cannot switch branch to a non-commit '%s'"),
index 5b6cebbb856cfc569079ad70f6825c76ea8e3cba..68105ecb2de297fc6b7ec3e5b50b0155dafbd8c8 100644 (file)
@@ -162,7 +162,7 @@ static NORETURN void die_push_simple(struct branch *branch,
                advice_pushdefault_maybe = _("\n"
                                 "To choose either option permanently, "
                                 "see push.default in 'git help config'.\n");
-       if (git_branch_track != BRANCH_TRACK_SIMPLE)
+       if (the_repository->config_values.git_branch_track != BRANCH_TRACK_SIMPLE)
                advice_automergesimple_maybe = _("\n"
                                 "To avoid automatically configuring "
                                 "an upstream branch when its name\n"
index d537ab087a02e92916da62fd9360e64921a18f40..7239722e48801fe7678b8d64df663bae8622fb16 100644 (file)
@@ -3128,7 +3128,7 @@ static int module_create_branch(int argc, const char **argv, const char *prefix,
        };
 
        repo_config(the_repository, git_default_config, NULL);
-       track = git_branch_track;
+       track = the_repository->config_values.git_branch_track;
        argc = parse_options(argc, argv, prefix, options, usage, 0);
 
        if (argc != 3)
index 65919a6c525538e13dcc74df9b19d53d4301d806..437d14e1ae01dbe8eff119e23b1e2d5a98afdfe9 100644 (file)
@@ -66,7 +66,6 @@ enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
 enum eol core_eol = EOL_UNSET;
 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
 char *check_roundtrip_encoding;
-enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
 enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
 enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
 #ifndef OBJECT_CREATION_MODE
@@ -607,18 +606,20 @@ static int git_default_i18n_config(const char *var, const char *value)
 
 static int git_default_branch_config(const char *var, const char *value)
 {
+       struct repo_config_values *cfg = &the_repository->config_values;
+
        if (!strcmp(var, "branch.autosetupmerge")) {
                if (value && !strcmp(value, "always")) {
-                       git_branch_track = BRANCH_TRACK_ALWAYS;
+                       cfg->git_branch_track = BRANCH_TRACK_ALWAYS;
                        return 0;
                } else if (value && !strcmp(value, "inherit")) {
-                       git_branch_track = BRANCH_TRACK_INHERIT;
+                       cfg->git_branch_track = BRANCH_TRACK_INHERIT;
                        return 0;
                } else if (value && !strcmp(value, "simple")) {
-                       git_branch_track = BRANCH_TRACK_SIMPLE;
+                       cfg->git_branch_track = BRANCH_TRACK_SIMPLE;
                        return 0;
                }
-               git_branch_track = git_config_bool(var, value);
+               cfg->git_branch_track = git_config_bool(var, value);
                return 0;
        }
        if (!strcmp(var, "branch.autosetuprebase")) {
@@ -756,3 +757,8 @@ int git_default_config(const char *var, const char *value,
        /* Add other config variables here and to Documentation/config.adoc. */
        return 0;
 }
+
+void repo_config_values_init(struct repo_config_values *cfg)
+{
+       cfg->git_branch_track = BRANCH_TRACK_REMOTE;
+}
index 5caf73b4b8d41332c15400282e539710a7d4d3fc..bfcdffe83642cfc69e7544bd13d661bd4e7b672c 100644 (file)
@@ -2,6 +2,7 @@
 #define ENVIRONMENT_H
 
 #include "repo-settings.h"
+#include "branch.h"
 
 /* Double-check local_repo_env below if you add to this list. */
 #define GIT_DIR_ENVIRONMENT "GIT_DIR"
@@ -89,6 +90,9 @@ struct repo_config_values {
        /* core config values */
        char *attributes_file_path;
        int sparse_checkout;
+
+       /* branch config values */
+       enum branch_track git_branch_track;
 };
 
 /*
@@ -114,6 +118,8 @@ const char *strip_namespace(const char *namespaced_ref);
 int git_default_config(const char *, const char *,
                       const struct config_context *, void *);
 
+void repo_config_values_init(struct repo_config_values *cfg);
+
 /*
  * TODO: All the below state either explicitly or implicitly relies on
  * `the_repository`. We should eventually get rid of these and make the
index c7e75215ac2ab215c7bac325d2623373e6e2da0d..d308cd78bfc46ba1dd144528fd1420914250b973 100644 (file)
@@ -57,6 +57,7 @@ void initialize_repository(struct repository *repo)
        ALLOC_ARRAY(repo->index, 1);
        index_state_init(repo->index, repo);
        repo->check_deprecated_config = true;
+       repo_config_values_init(&repo->config_values);
 
        /*
         * When a command runs inside a repository, it learns what