From d5b551874d9f96971aaf221888b037532a1bfbb9 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Thu, 2 Apr 2026 23:16:40 +0100 Subject: [PATCH] ifcgit: pre-fill branch name when switching to a remote branch tip When a remote branch tip is checked out (resulting in detached HEAD), the new-branch name field is now pre-filled with the local equivalent of the remote branch name (generating a unique suffix if that name is already taken), so the commit button is immediately usable. See #7580 Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/tool/ifcgit.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/bonsai/bonsai/tool/ifcgit.py b/src/bonsai/bonsai/tool/ifcgit.py index 3cb9a7f227..7bfda6cc57 100644 --- a/src/bonsai/bonsai/tool/ifcgit.py +++ b/src/bonsai/bonsai/tool/ifcgit.py @@ -476,11 +476,28 @@ class IfcGit: if item.hexsha in lookup: for branch in lookup[item.hexsha]: if branch.name == props.display_branch: + if isinstance(branch, git.RemoteReference): + # Checking out a remote branch tip goes to detached HEAD. + # Pre-fill the new branch name field with the local equivalent + # so the user isn't blocked from committing without a hint. + local_name = branch.remote_head + props.new_branch_name = cls._unique_branch_name(repo, local_name) branch.checkout() return # NOTE this is calling the git binary in a subprocess repo.git.checkout(item.hexsha) + @classmethod + def _unique_branch_name(cls, repo: git.Repo, name: str) -> str: + """Return name if unused, otherwise name-2, name-3, etc.""" + existing = {h.name for h in repo.heads} + if name not in existing: + return name + i = 2 + while f"{name}-{i}" in existing: + i += 1 + return f"{name}-{i}" + @classmethod def delete_collection(cls, blender_collection: bpy.types.Collection) -> None: for obj in blender_collection.objects: