mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +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"]
|
repo = IfcGitData.data["repo"]
|
||||||
if props.commit_message == "":
|
if props.commit_message == "":
|
||||||
return False
|
return False
|
||||||
if (
|
if repo:
|
||||||
repo
|
if props.new_branch_name in [branch.name for branch in repo.branches]:
|
||||||
and repo.head.is_detached
|
cls.poll_message_set("Branch already exists!")
|
||||||
and (
|
return False
|
||||||
not tool.IfcGit.is_valid_ref_format(props.new_branch_name)
|
elif not tool.IfcGit.is_valid_ref_format(props.new_branch_name):
|
||||||
or props.new_branch_name in [branch.name for branch in repo.branches]
|
if repo.head.is_detached:
|
||||||
)
|
cls.poll_message_set("Branch name is invalid or empty!")
|
||||||
):
|
return False
|
||||||
cls.poll_message_set(
|
elif props.new_branch_name != "":
|
||||||
"The new branch name is invalid, please insert a valid branch name (eg. with no spaces, ...)"
|
cls.poll_message_set("Branch name is invalid!")
|
||||||
)
|
return False
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
|||||||
@@ -79,10 +79,12 @@ class IFCGIT_PT_panel(bpy.types.Panel):
|
|||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(props, "commit_message")
|
row.prop(props, "commit_message")
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
if IfcGitData.data["is_detached"]:
|
if IfcGitData.data["is_detached"]:
|
||||||
row = layout.row()
|
|
||||||
row.label(text="HEAD is detached, commit will create a branch", icon="ERROR")
|
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 = layout.row()
|
||||||
row.operator("ifcgit.commit_changes", icon="GREASEPENCIL")
|
row.operator("ifcgit.commit_changes", icon="GREASEPENCIL")
|
||||||
|
|||||||
@@ -27,11 +27,15 @@ def discard_uncommitted(ifcgit, ifc):
|
|||||||
|
|
||||||
|
|
||||||
def commit_changes(ifcgit, ifc, repo):
|
def commit_changes(ifcgit, ifc, repo):
|
||||||
|
"""Commit and create new branches as required"""
|
||||||
path_ifc = ifc.get_path()
|
path_ifc = ifc.get_path()
|
||||||
ifcgit.git_commit(path_ifc)
|
|
||||||
|
|
||||||
if repo.head.is_detached:
|
if repo.head.is_detached:
|
||||||
|
ifcgit.git_commit(path_ifc)
|
||||||
ifcgit.create_new_branch()
|
ifcgit.create_new_branch()
|
||||||
|
else:
|
||||||
|
ifcgit.checkout_new_branch(path_ifc)
|
||||||
|
ifcgit.git_commit(path_ifc)
|
||||||
|
|
||||||
|
|
||||||
def add_tag(ifcgit, repo):
|
def add_tag(ifcgit, repo):
|
||||||
|
|||||||
@@ -81,6 +81,16 @@ class IfcGit:
|
|||||||
def git_checkout(cls, path_file):
|
def git_checkout(cls, path_file):
|
||||||
IfcGitRepo.repo.git.checkout(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
|
@classmethod
|
||||||
def git_commit(cls, path_file):
|
def git_commit(cls, path_file):
|
||||||
props = bpy.context.scene.IfcGitProperties
|
props = bpy.context.scene.IfcGitProperties
|
||||||
|
|||||||
Reference in New Issue
Block a user