From 6452872e83b2ffda00c399237ba0b6f232bcb3c6 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Sun, 3 Dec 2023 16:15:09 +0000 Subject: [PATCH] BlenderBIM IFC Git allow branch creation from HEAD Previously you could only create branches by checking out an older revision, making changes and committing it. This was an annoyance as typically you are making changes to the HEAD of a branch, then you realise this should have been a branch - now you can create the branch on commit (#3096) --- .../blenderbim/bim/module/ifcgit/operator.py | 23 +++++++++---------- .../blenderbim/bim/module/ifcgit/ui.py | 6 +++-- src/blenderbim/blenderbim/core/ifcgit.py | 6 ++++- src/blenderbim/blenderbim/tool/ifcgit.py | 10 ++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py index 4efe9f871f..4cf00a4508 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py @@ -115,18 +115,17 @@ class CommitChanges(bpy.types.Operator): repo = IfcGitData.data["repo"] if props.commit_message == "": return False - if ( - repo - and repo.head.is_detached - and ( - not tool.IfcGit.is_valid_ref_format(props.new_branch_name) - or props.new_branch_name in [branch.name for branch in repo.branches] - ) - ): - cls.poll_message_set( - "The new branch name is invalid, please insert a valid branch name (eg. with no spaces, ...)" - ) - return False + if repo: + if props.new_branch_name in [branch.name for branch in repo.branches]: + cls.poll_message_set("Branch already exists!") + return False + elif not tool.IfcGit.is_valid_ref_format(props.new_branch_name): + if repo.head.is_detached: + cls.poll_message_set("Branch name is invalid or empty!") + return False + elif props.new_branch_name != "": + cls.poll_message_set("Branch name is invalid!") + return False return True def execute(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py index 7c18bd6e42..be8af38b00 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py @@ -79,10 +79,12 @@ class IFCGIT_PT_panel(bpy.types.Panel): row = layout.row() row.prop(props, "commit_message") + row = layout.row() if IfcGitData.data["is_detached"]: - row = layout.row() row.label(text="HEAD is detached, commit will create a branch", icon="ERROR") - row.prop(props, "new_branch_name") + else: + row.label(text="Optionally create a branch:") + row.prop(props, "new_branch_name") row = layout.row() row.operator("ifcgit.commit_changes", icon="GREASEPENCIL") diff --git a/src/blenderbim/blenderbim/core/ifcgit.py b/src/blenderbim/blenderbim/core/ifcgit.py index 463f734587..9ca1469c79 100644 --- a/src/blenderbim/blenderbim/core/ifcgit.py +++ b/src/blenderbim/blenderbim/core/ifcgit.py @@ -27,11 +27,15 @@ def discard_uncommitted(ifcgit, ifc): def commit_changes(ifcgit, ifc, repo): + """Commit and create new branches as required""" path_ifc = ifc.get_path() - ifcgit.git_commit(path_ifc) if repo.head.is_detached: + ifcgit.git_commit(path_ifc) ifcgit.create_new_branch() + else: + ifcgit.checkout_new_branch(path_ifc) + ifcgit.git_commit(path_ifc) def add_tag(ifcgit, repo): diff --git a/src/blenderbim/blenderbim/tool/ifcgit.py b/src/blenderbim/blenderbim/tool/ifcgit.py index fa7ed68937..e9f8640a99 100644 --- a/src/blenderbim/blenderbim/tool/ifcgit.py +++ b/src/blenderbim/blenderbim/tool/ifcgit.py @@ -81,6 +81,16 @@ class IfcGit: def git_checkout(cls, path_file): IfcGitRepo.repo.git.checkout(path_file) + @classmethod + def checkout_new_branch(cls, path_file): + """Create a branch and move uncommitted changes to this branch""" + props = bpy.context.scene.IfcGitProperties + if props.new_branch_name: + IfcGitRepo.repo.git.checkout(b=props.new_branch_name) + props.display_branch = props.new_branch_name + props.new_branch_name = "" + bpy.ops.ifcgit.refresh() + @classmethod def git_commit(cls, path_file): props = bpy.context.scene.IfcGitProperties