@@ -3142,6 +3142,12 @@ int file_exists(const char *f)
return lstat(f, &sb) == 0;
}
+int file_exists_as_file(const char *path)
+{
+ struct stat st;
+ return lstat(path, &st) == 0 && S_ISREG(st.st_mode);
+}
+
int repo_file_exists(struct repository *repo, const char *path)
{
if (repo != the_repository)
@@ -475,6 +475,7 @@ void dir_clear(struct dir_struct *dir);
int repo_file_exists(struct repository *repo, const char *path);
int file_exists(const char *);
+int file_exists_as_file(const char *);
int is_inside_dir(const char *dir);
int dir_inside_of(const char *subdir, const char *dir);
@@ -801,7 +801,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
char *oidstr = NULL;
file = repo_worktree_path(repo, GITMODULES_FILE);
- if (file_exists(file)) {
+ if (file_exists_as_file(file)) {
config_source.file = file;
} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
If .gitmodules exists in the working tree but is a directory, it would have just tried to use it as if it were a file. On a platform that needs FREAD_READS_DIRECTORIES, this would have been hidden by our own fopen() that pretends as if directory did not exist, so it is a no-op. Just to add some documentation value, make sure we check with file_exists_as_file() instead of file_exists(), the latter of which will be happy as long as the given path exists no matter what it is. Signed-off-by: Junio C Hamano <gitster@pobox.com> --- dir.c | 6 ++++++ dir.h | 1 + submodule-config.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-)