From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 4/4] submodule: ignore .gitmodules that is not a regular file
Date: Tue, 18 Jun 2024 16:44:35 -0700 [thread overview]
Message-ID: <20240618234436.4107855-5-gitster@pobox.com> (raw)
In-Reply-To: <20240618234436.4107855-1-gitster@pobox.com>
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(-)
diff --git a/dir.c b/dir.c
index 73f89f4d8c..d943da93df 100644
--- a/dir.c
+++ b/dir.c
@@ -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)
diff --git a/dir.h b/dir.h
index 1398a53fb4..3612dbbf9e 100644
--- a/dir.h
+++ b/dir.h
@@ -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);
diff --git a/submodule-config.c b/submodule-config.c
index ec45ea67b9..6c18ae3764 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -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) {
--
2.45.2-711-gd2c001ca14
prev parent reply other threads:[~2024-06-18 23:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-14 12:03 Non-blob .gitmodules and .gitattributes Alexey Pelykh
2024-06-14 15:35 ` Junio C Hamano
2024-06-14 15:43 ` Alexey Pelykh
2024-06-18 18:31 ` Jeff King
2024-06-18 19:07 ` Alexey Pelykh
2024-06-18 20:14 ` Junio C Hamano
2024-06-18 23:33 ` Jeff King
2024-06-18 23:44 ` [PATCH 0/4] .git{ignore,attributes} directories? Junio C Hamano
2024-06-18 23:44 ` [PATCH 1/4] .gitignore: introduce GITIGNORE_FILE CPP macro Junio C Hamano
2024-06-18 23:44 ` [PATCH 2/4] attr: notice and report read failure of .gitattributes files Junio C Hamano
2024-06-19 0:21 ` Eric Sunshine
2024-06-19 1:18 ` Junio C Hamano
2024-06-19 2:35 ` Eric Sunshine
2024-06-19 13:57 ` Jeff King
2024-06-20 16:20 ` Junio C Hamano
2024-06-18 23:44 ` [PATCH 3/4] exclude: notice and report read failure of .gitignore files Junio C Hamano
2024-06-18 23:44 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240618234436.4107855-5-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).