aboutsummaryrefslogtreecommitdiffstats
path: root/setup.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-03-21 14:55:13 -0700
committerJunio C Hamano <gitster@pobox.com>2024-03-21 14:55:13 -0700
commitdc97afdcb93ca683bf73b4ae2ff028c161206617 (patch)
tree6740497270b388d8282d17cf394cc0b10e11aee7 /setup.c
parent8be51c1f36e7891c2d9c934d9bb8a81970a0f04e (diff)
parent30b7c4bdcac27ac08a6caf2c70aff55763b9b3ab (diff)
downloadgit-dc97afdcb93ca683bf73b4ae2ff028c161206617.tar.gz
Merge branch 'jc/safe-implicit-bare'
Users with safe.bareRepository=explicit can still work from within $GIT_DIR of a seconary worktree (which resides at .git/worktrees/$name/) of the primary worktree without explicitly specifying the $GIT_DIR environment variable or the --git-dir=<path> option. * jc/safe-implicit-bare: setup: notice more types of implicit bare repositories
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/setup.c b/setup.c
index b2d9371ddc..0b798591c0 100644
--- a/setup.c
+++ b/setup.c
@@ -1243,6 +1243,32 @@ static const char *allowed_bare_repo_to_string(
return NULL;
}
+static int is_implicit_bare_repo(const char *path)
+{
+ /*
+ * what we found is a ".git" directory at the root of
+ * the working tree.
+ */
+ if (ends_with_path_components(path, ".git"))
+ return 1;
+
+ /*
+ * we are inside $GIT_DIR of a secondary worktree of a
+ * non-bare repository.
+ */
+ if (strstr(path, "/.git/worktrees/"))
+ return 1;
+
+ /*
+ * we are inside $GIT_DIR of a worktree of a non-embedded
+ * submodule, whose superproject is not a bare repository.
+ */
+ if (strstr(path, "/.git/modules/"))
+ return 1;
+
+ return 0;
+}
+
/*
* 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.
@@ -1372,7 +1398,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_implicit_bare_repo(dir->buf))
return GIT_DIR_DISALLOWED_BARE;
if (!ensure_valid_ownership(NULL, NULL, dir->buf, report))
return GIT_DIR_INVALID_OWNERSHIP;