Earlier, 45bb9162 (setup: allow cwd=.git w/ bareRepository=explicit, 2024-01-20) loosened the "safe.bareRepository=explicit" to allow Git operations inside ".git/" directory in the root level of a working tree of a non-bare repository. It used the fact that the $GIT_DIR you discover has ".git" as the last path component, if you descended into ".git" of a non-bare repository. Let's move the logic into a separate helper function. We can enhance this to detect the case where we are inside $GIT_DIR of a secondary worktree (where "ends with .git" trick does not work) in the next commit. Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> --- setup.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.c b/setup.c index a09b7b87ec..3081be4970 100644 --- a/setup.c +++ b/setup.c @@ -1231,6 +1231,11 @@ static const char *allowed_bare_repo_to_string( return NULL; } +static int is_repo_with_working_tree(const char *path) +{ + return ends_with_path_components(path, ".git"); +} + /* * We cannot decide in this function whether we are in the work tree or * not, since the config can only be read _after_ this function was called. @@ -1360,7 +1365,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, if (is_git_directory(dir->buf)) { trace2_data_string("setup", NULL, "implicit-bare-repository", dir->buf); if (get_allowed_bare_repo() == ALLOWED_BARE_REPO_EXPLICIT && - !ends_with_path_components(dir->buf, ".git")) + !is_repo_with_working_tree(dir->buf)) return GIT_DIR_DISALLOWED_BARE; if (!ensure_valid_ownership(NULL, NULL, dir->buf, report)) return GIT_DIR_INVALID_OWNERSHIP; -- 2.44.0-165-ge09f1254c5