From 3884260bcf834e768651d2062a3419537dd76dc2 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Tue, 23 May 2023 22:45:41 +0100 Subject: [PATCH] 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. --- .../blenderbim/bim/module/ifcgit/operator.py | 4 +-- src/blenderbim/blenderbim/tool/ifcgit.py | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py index 38dfe2c681..1253c5bbf5 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py @@ -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"} diff --git a/src/blenderbim/blenderbim/tool/ifcgit.py b/src/blenderbim/blenderbim/tool/ifcgit.py index 2cd8ca9cb1..641d0ad295 100644 --- a/src/blenderbim/blenderbim/tool/ifcgit.py +++ b/src/blenderbim/blenderbim/tool/ifcgit.py @@ -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