Operator to run git diff on current ifc file

Short demo - https://imgur.com/a/TvnztNy
This commit is contained in:
Andrej730
2025-04-30 12:21:34 +05:00
parent 07f42b9126
commit 3bedbfb82c
5 changed files with 52 additions and 0 deletions
@@ -38,6 +38,7 @@ classes = (
operator.RefreshGit,
operator.SwitchRevision,
operator.InstallGit,
operator.RunGitDiff,
prop.IfcGitTag,
prop.IfcGitListItem,
prop.IfcGitProperties,
@@ -409,3 +409,25 @@ class InstallGit(bpy.types.Operator):
core.install_git(tool.IfcGit, self)
refresh()
return {"FINISHED"}
class RunGitDiff(bpy.types.Operator):
"""Run `git diff` for the current version of IFC file and the last saved one."""
bl_label = "Git Diff"
bl_idname = "ifcgit.git_diff"
bl_options = set()
@classmethod
def poll(cls, context):
if not tool.Ifc.get():
cls.poll_message_set("No IFC file loaded.")
return False
if not tool.Ifc.get_path():
cls.poll_message_set("Current IFC file was never saved.")
return False
return True
def execute(self, context):
core.run_git_diff(tool.IfcGit, self)
return {"FINISHED"}
@@ -283,3 +283,5 @@ class IFCGIT_PT_revision_inspector(bpy.types.Panel):
"ifcgit.object_log",
icon="TEXT",
)
row = layout.row()
row.operator("ifcgit.git_diff")
+4
View File
@@ -142,3 +142,7 @@ def install_git(ifcgit: tool.IfcGit, operator: bpy.types.Operator) -> None:
ifcgit.install_git_windows(operator=operator)
else:
print("install_git() not implemented")
def run_git_diff(ifcgit: tool.IfcGit, operator: bpy.types.Operator) -> None:
ifcgit.run_git_diff(operator)
+23
View File
@@ -570,6 +570,29 @@ class IfcGit:
except FileNotFoundError:
operator.report({"ERROR"}, "Winget is not available. Make sure Windows Package Manager is installed.")
@classmethod
def run_git_diff(cls, operator: bpy.types.Operator) -> None:
path = tool.Ifc.get_path()
ifc_file = tool.Ifc.get()
ifc_str = ifc_file.to_string()
# Avoid `text=True` as it's causing issues with colorful output.
result = subprocess.run(
("git", "diff", "--no-index", "--color=always", "--", path, "-"),
input=ifc_str.encode(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
if result.returncode == 0:
operator.report({"INFO"}, "No changes since last save.")
return
elif result.returncode == 1:
print(result.stdout.decode())
operator.report({"INFO"}, "See system console for git diff output.")
return
print(result)
raise Exception("Error running git diff, see system console.")
class IfcGitRepo:
repo: git.Repo = None