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 (<worktree>/.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 <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Brian Gan <brgan@google.com>
This commit is contained in:
Gavin Mak authored and gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-11-12 16:07:48 -08:00
1 parent f01eb8774f
commit 7cbd9d1762
2 files changed
+10 -3

No files matched your search

+4 -3
View File
@@ -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)
+6
View File
@@ -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")
)