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 <christian.couder@gmail.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tian Yuchen committed
Jun 20, 2026 at 22:09 UTC
a472af8bfdebe98e4e48a76b83e5424708cb42ef
2 files changed
+4
-4
environment.c
+2
-2
@@ -142,14 +142,14 @@ int is_bare_repository(void)
142
143
int repo_protect_ntfs(struct repository *repo)
144
{
145
- return repo->gitdir ?
145
+ return (repo && repo->initialized) ?
146
repo_config_values(repo)->protect_ntfs :
147
PROTECT_NTFS_DEFAULT;
148
}
149
150
int repo_protect_hfs(struct repository *repo)
151
{
152
- return repo->gitdir ?
152
+ return (repo && repo->initialized) ?
153
repo_config_values(repo)->protect_hfs :
154
PROTECT_HFS_DEFAULT;
155
}
environment.h
+2
-2
@@ -127,8 +127,8 @@ int git_default_core_config(const char *var, const char *value,
127
128
/*
129
* Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.
130
- * They check `repo->gitdir` to prevent calling repo_config_values()
131
- * before the configuration is loaded or in bare environments.
130
+ * They check `repo->initialized` to prevent calling `repo_config_values()`
131
+ * before the repository setup is fully complete or in non-git environments.
132
*/
133
int repo_protect_hfs(struct repository *repo);
134
int repo_protect_ntfs(struct repository *repo);