From 7cbd9d176286a4c4e8006534785d1dea65629aa9 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Tue, 10 Nov 2026 00:37:50 +0000 Subject: [PATCH] project: only unset core.bare when it is true When creating a gitdir, _InitGitDir spawned `git config --unset-all core.bare` for every non-mirror project. That is needed when `git init` wrote `core.bare = true`, as it does for a gitdir under .repo/project-objects. For a local worktree gitdir (/.git, as with --use-local-gitdirs) `git init` already writes `core.bare = false`, so the spawn only removed a setting that was already correct. Checked on git 1.9.1 (the oldest version repo supports), 2.7.4, 2.20.1 and 2.56. Unset core.bare on non-mirror repositories only when it is currently true. Local worktree gitdirs now keep the `core.bare = false` that `git init` wrote. Bug: 543101585 Change-Id: I662ffce61dc68ebca921941c1a5e5ebce2d22338 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/655965 Tested-by: Gavin Mak Commit-Queue: Gavin Mak Reviewed-by: Brian Gan --- project.py | 7 ++++--- tests/test_project.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/project.py b/project.py index 308d0f8ad..f1d26c5a2 100644 --- a/project.py +++ b/project.py @@ -4511,9 +4511,10 @@ class Project: "filter.lfs.process", "git-lfs filter-process --skip", ) - curr_config.SetBoolean( - "core.bare", True if self.manifest.IsMirror else None - ) + if self.manifest.IsMirror: + curr_config.SetBoolean("core.bare", True) + elif curr_config.GetBoolean("core.bare"): + curr_config.SetBoolean("core.bare", None) if tmp_gitdir: platform_utils.rename(tmp_gitdir, self.gitdir) diff --git a/tests/test_project.py b/tests/test_project.py index 79307ab5f..85c8cd906 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -5179,8 +5179,14 @@ class InitGitDirConfigTests(unittest.TestCase): any("--replace-all" in cmd for cmd in seen_cmds), f"Expected BatchWrites to avoid --replace-all, got {seen_cmds}", ) + self.assertFalse( + any("core.bare" in cmd for cmd in seen_cmds), + f"Expected local init to avoid core.bare config spawns: " + f"{seen_cmds}", + ) reloaded = git_config.GitConfig.ForRepository(gitdir=proj.gitdir) fresh = reloaded._ReadGit() + self.assertEqual(["false"], fresh.get("core.bare")) self.assertEqual( ["git-lfs smudge --skip -- %f"], fresh.get("filter.lfs.smudge") )