aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlamide Caleb Bello <belkid98@gmail.com>2026-02-16 17:38:27 +0100
committerJunio C Hamano <gitster@pobox.com>2026-02-26 07:22:53 -0800
commitcf50830ce1d1b95a44f9d095ff868e7df1495863 (patch)
treecd822cab52c3abbc1685d3c5f3568c5e6dc5ac1e
parent4021751558126d39b642503e7ef4768131df45e7 (diff)
downloadgit-cf50830ce1d1b95a44f9d095ff868e7df1495863.tar.xz
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>
-rw-r--r--branch.h2
-rw-r--r--builtin/branch.c3
-rw-r--r--builtin/checkout.c3
-rw-r--r--builtin/push.c3
-rw-r--r--builtin/submodule--helper.c3
-rw-r--r--environment.c12
-rw-r--r--environment.h4
7 files changed, 19 insertions, 11 deletions
diff --git a/branch.h b/branch.h
index ec2f35fda4..3dc6e2a0ff 100644
--- 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. */
/**
diff --git a/builtin/branch.c b/builtin/branch.c
index c577b5d20f..a1a43380d0 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -724,6 +724,7 @@ int cmd_branch(int argc,
static struct ref_sorting *sorting;
struct string_list sorting_options = STRING_LIST_INIT_DUP;
struct ref_format format = REF_FORMAT_INIT;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
int ret;
struct option options[] = {
@@ -795,7 +796,7 @@ int cmd_branch(int argc,
if (!sorting_options.nr)
string_list_append(&sorting_options, "refname");
- track = git_branch_track;
+ track = cfg->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 66b69df6e6..736e20f808 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1588,6 +1588,7 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts,
static int checkout_branch(struct checkout_opts *opts,
struct branch_info *new_branch_info)
{
+ struct repo_config_values *cfg = repo_config_values(the_repository);
int noop_switch = (!new_branch_info->name &&
!opts->new_branch &&
!opts->force_detach);
@@ -1631,7 +1632,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 = cfg->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..7100ffba5d 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -151,6 +151,7 @@ static NORETURN void die_push_simple(struct branch *branch,
const char *advice_pushdefault_maybe = "";
const char *advice_automergesimple_maybe = "";
const char *short_upstream = branch->merge[0]->src;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
skip_prefix(short_upstream, "refs/heads/", &short_upstream);
@@ -162,7 +163,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 (cfg->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..594cd107b3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -3126,9 +3126,10 @@ static int module_create_branch(int argc, const char **argv, const char *prefix,
N_("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>"),
NULL
};
+ struct repo_config_values *cfg = repo_config_values(the_repository);
repo_config(the_repository, git_default_config, NULL);
- track = git_branch_track;
+ track = cfg->branch_track;
argc = parse_options(argc, argv, prefix, options, usage, 0);
if (argc != 3)
diff --git a/environment.c b/environment.c
index 390af1ce54..1bc3adb75b 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,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 = repo_config_values(the_repository);
+
if (!strcmp(var, "branch.autosetupmerge")) {
if (value && !strcmp(value, "always")) {
- git_branch_track = BRANCH_TRACK_ALWAYS;
+ cfg->branch_track = BRANCH_TRACK_ALWAYS;
return 0;
} else if (value && !strcmp(value, "inherit")) {
- git_branch_track = BRANCH_TRACK_INHERIT;
+ cfg->branch_track = BRANCH_TRACK_INHERIT;
return 0;
} else if (value && !strcmp(value, "simple")) {
- git_branch_track = BRANCH_TRACK_SIMPLE;
+ cfg->branch_track = BRANCH_TRACK_SIMPLE;
return 0;
}
- git_branch_track = git_config_bool(var, value);
+ cfg->branch_track = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "branch.autosetuprebase")) {
@@ -761,4 +762,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
{
cfg->attributes_file = NULL;
cfg->apply_sparse_checkout = 0;
+ cfg->branch_track = BRANCH_TRACK_REMOTE;
}
diff --git a/environment.h b/environment.h
index 2e24160322..4bfd798757 100644
--- a/environment.h
+++ b/environment.h
@@ -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 {
/* section "core" config values */
char *attributes_file;
int apply_sparse_checkout;
+
+ /* section "branch" config values */
+ enum branch_track branch_track;
};
struct repo_config_values *repo_config_values(struct repository *repo);