mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-07 00:11:36 +00:00
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)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user