mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-05 23:41:44 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user