BlenderBIM set gitattributes and autocrlf

Force Git to always treat IFC files as text.
Store IFC in Git with LF line-endings, but checked-out files are
CRLF on Windows.
This commit is contained in:
Bruno Postle
2023-05-23 22:45:41 +01:00
parent 27655dcf35
commit 3884260bcf
2 changed files with 26 additions and 3 deletions
@@ -137,7 +137,7 @@ class CommitChanges(bpy.types.Operator):
class AddTag(bpy.types.Operator):
"""Tag selected revision"""
bl_label = "Add tag"
bl_label = "Tag selected revision"
bl_idname = "ifcgit.add_tag"
bl_options = {"REGISTER"}
@@ -260,7 +260,7 @@ class Push(bpy.types.Operator):
props = context.scene.IfcGitProperties
repo = IfcGitData.data["repo"]
remote = repo.remotes[props.select_remote]
remote.push()
remote.push(refspec=IfcGitData.data["repo"].active_branch.name)
return {"FINISHED"}
+24 -1
View File
@@ -16,10 +16,24 @@ class IfcGit:
@classmethod
def init_repo(cls, path_dir):
IfcGitRepo.repo = git.Repo.init(path_dir)
autocrlf = "input"
if os.name == "nt":
autocrlf = "true"
IfcGitRepo.repo.config_writer().set_value("core", "autocrlf", autocrlf)
cls.config_info_attributes(IfcGitRepo.repo)
@classmethod
def clone_repo(cls, remote_url, local_folder):
IfcGitRepo.repo = git.Repo.clone_from(remote_url, local_folder)
autocrlf = "input"
if os.name == "nt":
autocrlf = "true"
IfcGitRepo.repo = git.Repo.clone_from(
url=remote_url,
to_path=local_folder,
allow_unsafe_options=True,
multi_options=["--config core.autocrlf=" + autocrlf],
)
cls.config_info_attributes(IfcGitRepo.repo)
return IfcGitRepo.repo
@classmethod
@@ -355,6 +369,15 @@ class IfcGit:
config_writer.set_value(section, "cmd", "ifcmerge $BASE $LOCAL $REMOTE $MERGED")
config_writer.set_value(section, "trustExitCode", True)
@classmethod
def config_info_attributes(cls, repo):
"""Set IFC files as text in .git/info/attributes"""
path_attributes = os.path.join(repo.git_dir, "info", "attributes")
if not os.path.exists(path_attributes):
with open(path_attributes, "w") as f:
f.write("*.ifc text\n")
f.write("*.IFC text")
@classmethod
def execute_merge(cls, path_ifc, operator):
props = bpy.context.scene.IfcGitProperties