mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Recover external git repo changes, fixes #5311
IfcGit didn't cope gracefully when commits and/or repositories vanished unexpectedly
This commit is contained in:
@@ -154,15 +154,17 @@ class IfcGitData:
|
||||
@classmethod
|
||||
def commit(cls):
|
||||
props = bpy.context.scene.IfcGitProperties
|
||||
if len(props.ifcgit_commits) > 0:
|
||||
if cls.repo() and len(props.ifcgit_commits) > 0:
|
||||
item = props.ifcgit_commits[props.commit_index]
|
||||
if cls.repo():
|
||||
try:
|
||||
return cls.repo().commit(rev=item.hexsha)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def current_revision(cls):
|
||||
props = bpy.context.scene.IfcGitProperties
|
||||
if len(props.ifcgit_commits) > 0:
|
||||
if cls.repo() and cls.repo().head.is_valid() and len(props.ifcgit_commits) > 0:
|
||||
return tool.IfcGitRepo.repo.commit()
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import bpy
|
||||
import time
|
||||
import os
|
||||
|
||||
from bonsai.bim.module.ifcgit.data import IfcGitData
|
||||
|
||||
|
||||
@@ -32,7 +34,7 @@ class IFCGIT_PT_panel(bpy.types.Panel):
|
||||
|
||||
row = layout.row()
|
||||
if path_ifc:
|
||||
if IfcGitData.data["repo"]:
|
||||
if IfcGitData.data["repo"] and os.path.exists(IfcGitData.data["repo"].git_dir):
|
||||
name_ifc = IfcGitData.data["name_ifc"]
|
||||
row.label(text=IfcGitData.data["working_dir"], icon="SYSTEM")
|
||||
if name_ifc in IfcGitData.data["untracked_files"]:
|
||||
@@ -44,6 +46,7 @@ class IFCGIT_PT_panel(bpy.types.Panel):
|
||||
else:
|
||||
row.label(text=name_ifc, icon="FILE")
|
||||
else:
|
||||
IfcGitData.load()
|
||||
row.operator(
|
||||
"ifcgit.createrepo",
|
||||
text="Create '" + IfcGitData.data["dir_name"] + "' repository",
|
||||
@@ -193,7 +196,10 @@ class COMMIT_UL_List(bpy.types.UIList):
|
||||
|
||||
# TODO Figure how this "item" can be acesse in "data.py"
|
||||
# so it's possible to move the ".commit"
|
||||
commit = IfcGitData.data["repo"].commit(rev=item.hexsha)
|
||||
try:
|
||||
commit = IfcGitData.data["repo"].commit(rev=item.hexsha)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
lookup = IfcGitData.data["branches_by_hexsha"]
|
||||
refs = ""
|
||||
|
||||
@@ -79,7 +79,7 @@ class IfcGit:
|
||||
else:
|
||||
return None
|
||||
|
||||
if IfcGitRepo.repo is not None and IfcGitRepo.repo.working_dir == path_dir:
|
||||
if IfcGitRepo.repo is not None and os.path.exists(IfcGitRepo.repo.git_dir) and IfcGitRepo.repo.working_dir == path_dir:
|
||||
return IfcGitRepo.repo
|
||||
|
||||
try:
|
||||
@@ -88,9 +88,11 @@ class IfcGit:
|
||||
parentdir_path = os.path.abspath(os.path.join(path_dir, os.pardir))
|
||||
if parentdir_path == path_dir:
|
||||
# root folder
|
||||
IfcGitRepo.repo = None
|
||||
return None
|
||||
return cls.repo_from_path(parentdir_path)
|
||||
except git.exc.NoSuchPathError:
|
||||
IfcGitRepo.repo = None
|
||||
return None
|
||||
if repo:
|
||||
IfcGitRepo.repo = repo
|
||||
|
||||
Reference in New Issue
Block a user