From e4ff87cb011f2cc7295b94f6f8bf1aa7059062c4 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Fri, 26 May 2023 08:28:20 +0100 Subject: [PATCH] BBIM Ensure LF end-of-line in Git repo (#3096) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git auto text detection seems to fail with IFC files, possibly due to long lines. So we now force detection as text which ensures conversion from CRLF to LF when adding to the repository. We also convert the local IFC file to LF otherwise Git thinks that the local file is out-of-sync with the repo version ¯\_(ツ)_/¯ --- src/blenderbim/blenderbim/tool/ifcgit.py | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/blenderbim/blenderbim/tool/ifcgit.py b/src/blenderbim/blenderbim/tool/ifcgit.py index 641d0ad295..80520c6845 100644 --- a/src/blenderbim/blenderbim/tool/ifcgit.py +++ b/src/blenderbim/blenderbim/tool/ifcgit.py @@ -16,22 +16,13 @@ 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): - 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 @@ -78,6 +69,8 @@ class IfcGit: @classmethod def add_file_to_repo(cls, repo, path_file): + if os.name == "nt": + cls.dos2unix(path_file) repo.index.add(path_file) repo.index.commit(message="Added " + os.path.relpath(path_file, repo.working_dir)) bpy.ops.ifcgit.refresh() @@ -90,6 +83,8 @@ class IfcGit: def git_commit(cls, path_file): props = bpy.context.scene.IfcGitProperties repo = IfcGitRepo.repo + if os.name == "nt": + cls.dos2unix(path_file) repo.index.add(path_file) repo.index.commit(message=props.commit_message) props.commit_message = "" @@ -375,8 +370,16 @@ class IfcGit: 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") + # attributes patterns are case-insensitive + f.write("*.ifc text") + + @classmethod + def dos2unix(cls, path_file): + with open(path_file, "rb") as infile: + content = infile.read() + with open(path_file, "wb") as output: + for line in content.splitlines(): + output.write(line + b"\n") @classmethod def execute_merge(cls, path_ifc, operator):