From a472af8bfdebe98e4e48a76b83e5424708cb42ef Mon Sep 17 00:00:00 2001 From: Tian Yuchen Date: Sat, 20 Jun 2026 22:09:57 +0800 Subject: [PATCH] environment: use 'repo->initialized' for repo_protect_hfs() and repo_protect_ntfs() To match how we refrain from calling repo_config_values() on an uninitialized instance of a repository object in other two topics that deal with ignore_case and trust_executable_bit, check the repo->initialized bit instead of the repo->gitdir member. Mentored-by: Christian Couder Mentored-by: Ayush Chandekar Mentored-by: Olamide Caleb Bello Signed-off-by: Tian Yuchen Signed-off-by: Junio C Hamano --- environment.c | 4 ++-- environment.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/environment.c b/environment.c index 683fe1b4d3..f34f6fc750 100644 --- a/environment.c +++ b/environment.c @@ -142,14 +142,14 @@ int is_bare_repository(void) int repo_protect_ntfs(struct repository *repo) { - return repo->gitdir ? + return (repo && repo->initialized) ? repo_config_values(repo)->protect_ntfs : PROTECT_NTFS_DEFAULT; } int repo_protect_hfs(struct repository *repo) { - return repo->gitdir ? + return (repo && repo->initialized) ? repo_config_values(repo)->protect_hfs : PROTECT_HFS_DEFAULT; } diff --git a/environment.h b/environment.h index fdd9775900..b1ae4a70de 100644 --- a/environment.h +++ b/environment.h @@ -127,8 +127,8 @@ int git_default_core_config(const char *var, const char *value, /* * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`. - * They check `repo->gitdir` to prevent calling repo_config_values() - * before the configuration is loaded or in bare environments. + * They check `repo->initialized` to prevent calling `repo_config_values()` + * before the repository setup is fully complete or in non-git environments. */ int repo_protect_hfs(struct repository *repo); int repo_protect_ntfs(struct repository *repo);