git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[Outreachy PATCH RFC 3/3] environment: move "branch.autoSetupMerge" into `struct config_values`

From
Olamide Caleb Bello <belkid98@gmail.com>
Date
Jan 12, 2026, 12:59 UTC
Message-ID
<2ea3bd7816624bc03426ded68ddd1e9c15f19127.1768217572.git.belkid98@gmail.com>
In-Reply-To
<cover.1768217572.git.belkid98@gmail.com>

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 config_values` which holds all values parsed by `git_default_config()` and can be accessed per repo via `git_default_config()`. This would mean we do not have to remove code from `git_default_branch_config()`, thereby retaining the same behaviour.

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>
---
 builtin/branch.c            |  2 +-
 builtin/checkout.c          |  2 +-
 builtin/push.c              |  2 +-
 builtin/submodule--helper.c |  2 +-
 config.c                    |  5 +++++
 config.h                    |  4 ++++
 environment.c               | 10 +++++-----
 repository.c                |  1 +
 8 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index c577b5d20f..6dde426e90 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -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->cfg_values->git_branch_track;
 
 	head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
 				   0, &head_oid, NULL);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 261699e2f5..0b8aa6b45a 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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->cfg_values->git_branch_track;
 
 	if (new_branch_info->name && !new_branch_info->commit)
 		die(_("Cannot switch branch to a non-commit '%s'"),
diff --git a/builtin/push.c b/builtin/push.c
index 5b6cebbb85..14967002ae 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -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->cfg_values->git_branch_track != BRANCH_TRACK_SIMPLE)
 		advice_automergesimple_maybe = _("\n"
 				 "To avoid automatically configuring "
 				 "an upstream branch when its name\n"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index d537ab087a..0e2226b3c8 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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->cfg_values->git_branch_track;
 	argc = parse_options(argc, argv, prefix, options, usage, 0);
 
 	if (argc != 3)
diff --git a/config.c b/config.c
index 8b882f64ae..c19df32ad6 100644
--- a/config.c
+++ b/config.c
@@ -1766,6 +1766,11 @@ void config_values_clear(struct config_values *cfg)
 	free(cfg->attributes_file_path);
 }
 
+void config_values_init_defaults(struct config_values *cfg)
+{
+	cfg->git_branch_track = BRANCH_TRACK_REMOTE;
+}
+
 void git_configset_init(struct config_set *set)
 {
 	hashmap_init(&set->config_hash, config_set_element_cmp, NULL, 0);
diff --git a/config.h b/config.h
index 21d65c440e..62032346e3 100644
--- a/config.h
+++ b/config.h
@@ -5,6 +5,7 @@
 #include "string-list.h"
 #include "repository.h"
 #include "parse.h"
+#include "branch.h"
 
 /**
  * The config API gives callers a way to access Git configuration files
@@ -142,6 +143,8 @@ struct config_values {
 	char *attributes_file_path;
 	int sparse_checkout;
 
+	/* branch config values */
+	enum branch_track git_branch_track;
 };
 #define CONFIG_CONTEXT_INIT { 0 }
 
@@ -195,6 +198,7 @@ int git_config_from_blob_oid(config_fn_t fn, const char *name,
 void git_config_push_parameter(const char *text);
 void git_config_push_env(const char *spec);
 int git_config_from_parameters(config_fn_t fn, void *data);
+void config_values_init_defaults(struct config_values *cfg);
 void config_values_clear(struct config_values *cfg);
 
 /*
diff --git a/environment.c b/environment.c
index 15b63cdc4a..207e63f519 100644
--- a/environment.c
+++ b/environment.c
@@ -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,19 @@ 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 config_values *cfg = the_repository->cfg_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")) {
diff --git a/repository.c b/repository.c
index 3ad944e71c..98237eceaa 100644
--- a/repository.c
+++ b/repository.c
@@ -56,6 +56,7 @@ void initialize_repository(struct repository *repo)
 	repo->parsed_objects = parsed_object_pool_new(repo);
 	ALLOC_ARRAY(repo->index, 1);
 	CALLOC_ARRAY(repo->cfg_values, 1);
+	config_values_init_defaults(repo->cfg_values);
 	index_state_init(repo->index, repo);
 	repo->check_deprecated_config = true;
 
-- 
2.34.1
Previous: Olamide Caleb BelloNext: Olamide Caleb Bello
Message 6 of 71 in “store git_default_config() parsed values in new config struct”
  1. 0/3 store git_default_config() parsed values in new config structOlamide Caleb Bello, Jan 12, 2026
  2. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 12, 2026
  3. Phillip WoodJan 12, 2026
  4. Bello OlamideJan 12, 2026
  5. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 12, 2026
  6. 3/3 environment: move "branch.autoSetupMerge" into `struct config_values`Olamide Caleb Bello, Jan 12, 2026
  7. 0/3 store git_default_config() parsed values in new config structOlamide Caleb Bello, Jan 13, 2026
  8. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 13, 2026
  9. Junio C HamanoJan 13, 2026
  10. Bello OlamideJan 14, 2026
  11. 2/3 environment: environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 13, 2026
  12. Junio C HamanoJan 13, 2026
  13. Bello OlamideJan 14, 2026
  14. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 13, 2026
  15. Junio C HamanoJan 13, 2026
  16. Bello OlamideJan 14, 2026
  17. Bello OlamideJan 15, 2026
  18. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Jan 17, 2026
  19. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 17, 2026
  20. Toon ClaesJan 22, 2026
  21. Bello OlamideJan 22, 2026
  22. Phillip WoodJan 22, 2026
  23. Bello OlamideJan 22, 2026
  24. 2/3 environment: environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 17, 2026
  25. Toon ClaesJan 22, 2026
  26. Bello OlamideJan 22, 2026
  27. Phillip WoodJan 22, 2026
  28. Bello OlamideJan 22, 2026
  29. Phillip WoodJan 23, 2026
  30. Bello OlamideJan 23, 2026
  31. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 17, 2026
  32. Phillip WoodJan 22, 2026
  33. Bello OlamideJan 22, 2026
  34. Bello OlamideJan 20, 2026
  35. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  36. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 24, 2026
  37. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 24, 2026
  38. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  39. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  40. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 24, 2026
  41. Junio C HamanoJan 29, 2026
  42. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 24, 2026
  43. Junio C HamanoJan 29, 2026
  44. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  45. Junio C HamanoJan 29, 2026
  46. Junio C HamanoJan 30, 2026
  47. Junio C HamanoJan 30, 2026
  48. Bello OlamideJan 29, 2026
  49. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Feb 3, 2026
  50. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Feb 3, 2026
  51. Phillip WoodFeb 4, 2026
  52. Bello OlamideFeb 9, 2026
  53. Junio C HamanoFeb 7, 2026
  54. Phillip WoodFeb 8, 2026
  55. Bello OlamideFeb 9, 2026
  56. Bello OlamideFeb 10, 2026
  57. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Feb 3, 2026
  58. Phillip WoodFeb 4, 2026
  59. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Feb 3, 2026
  60. Phillip WoodFeb 4, 2026
  61. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Feb 16, 2026
  62. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Feb 16, 2026
  63. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Feb 16, 2026
  64. Christian CouderFeb 26, 2026
  65. Junio C HamanoFeb 26, 2026
  66. Bello OlamideFeb 26, 2026
  67. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Feb 16, 2026
  68. Junio C HamanoFeb 17, 2026
  69. Bello OlamideFeb 18, 2026
  70. Christian CouderFeb 26, 2026
  71. Junio C HamanoFeb 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.