git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] setup: detect to be in $GIT_DIR with a new helper

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 8, 2024, 21:19 UTC
Message-ID
<20240308211957.3758770-2-gitster@pobox.com>
In-Reply-To
<20240308211957.3758770-1-gitster@pobox.com>

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@pobox.com>
---
 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 17 in “setup: allow cwd=.git w/ bareRepository=explicit”
  1. setup: allow cwd=.git w/ bareRepository=explicitKyle Lippincott via GitGitGadget, Jan 20, 2024
  2. Junio C HamanoJan 20, 2024
  3. Kyle LippincottJan 22, 2024
  4. Junio C HamanoMar 6, 2024
  5. 0/2 Loosening safe.bareRepository=explicit even furtherJunio C Hamano, Mar 8, 2024
  6. 2/2 setup: make bareRepository=explicit work in GIT_DIR of a secondary worktreeJunio C Hamano, Mar 8, 2024
  7. Junio C HamanoMar 8, 2024
  8. Kyle LippincottMar 8, 2024
  9. Junio C HamanoMar 8, 2024
  10. Kyle LippincottMar 9, 2024
  11. Junio C HamanoMar 9, 2024
  12. Kyle MeyerMar 9, 2024
  13. Junio C HamanoMar 9, 2024
  14. 1/2 setup: detect to be in $GIT_DIR with a new helperJunio C Hamano, Mar 8, 2024
  15. setup: notice more types of implicit bare repositoriesJunio C Hamano, Mar 9, 2024
  16. Kyle LippincottMar 11, 2024
  17. Junio C HamanoMar 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.