]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: use 'repo->initialized' for repo_protect_hfs() and repo_protect_ntfs()
authorTian Yuchen <cat@malon.dev>
Sat, 20 Jun 2026 14:09:57 +0000 (22:09 +0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Jun 2026 15:16:40 +0000 (08:16 -0700)
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>
environment.c
environment.h

index 683fe1b4d35257f6dd209dc2c8cbf816b9f8cb79..f34f6fc7507f6b2c850b9295bbf2880120c400ef 100644 (file)
@@ -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;
 }
index fdd9775900701d9b2c26a2c78f60ec8c852ba88c..b1ae4a70decc7c9b945c41c9760701006898d8ec 100644 (file)
@@ -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);