Bonsai: default new Git repos to a main branch

IfcGit.init_repo() called git.Repo.init() with no branch argument, so
newly initialised repositories inherited whatever the machine's global
init.defaultBranch was set to, falling back to git's legacy "master"
default when that config was absent. Check the global init.defaultBranch
setting first, and only pass initial_branch="main" when it is unset, so
existing user configuration is still respected.

Addresses the "default branch should be main" item from issue #3096.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Petru Conduraru
2026-07-16 17:31:15 +03:00
parent d9d1824886
commit f1b9d50552
+8 -1
View File
@@ -61,7 +61,14 @@ class IfcGit(bonsai.core.tool.IfcGit):
@classmethod
def init_repo(cls, path_dir: str) -> None:
IfcGitRepo.repo = git.Repo.init(path_dir)
kwargs = {}
try:
git.Git().config("--global", "--get", "init.defaultBranch")
except git.exc.GitCommandError:
# global init.defaultBranch isn't configured, so git would otherwise
# fall back to its legacy "master" default; use "main" instead
kwargs["initial_branch"] = "main"
IfcGitRepo.repo = git.Repo.init(path_dir, **kwargs)
cls.config_info_attributes(IfcGitRepo.repo)
@classmethod