From ddef4820d05632d1e5cd1192df41258b43af8e51 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Fri, 16 Jun 2023 19:30:20 +0100 Subject: [PATCH] BlenderBIM Git merge asymmetry heuristic (#3096) `ifcmerge` is asymmetrical. When both branches have new entities, either local or remote step Ids need to be renumbered to resolve the merge conflict. If the remote branch is 'origin/main' or 'main' we preserve remote Ids, otherwise we preserve local Ids. This should support a workflow where a local 'main' branch is kept pristine, but other local branches are treated as disposable; it should also support a workflow where multiple authors access a shared 'origin'. --- src/blenderbim/blenderbim/tool/ifcgit.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/tool/ifcgit.py b/src/blenderbim/blenderbim/tool/ifcgit.py index ef9b4b770c..5851dcbfce 100644 --- a/src/blenderbim/blenderbim/tool/ifcgit.py +++ b/src/blenderbim/blenderbim/tool/ifcgit.py @@ -421,13 +421,19 @@ class IfcGit: for branch in lookup[item.hexsha]: if branch.name == props.display_branch: # this is a branch! + if re.match("^(origin/)?(HEAD|main|master)$", branch.name): + # preserve remote IDs in origin/main or main + mergetool = "ifcmerge" + else: + # rewrite remote IDs + mergetool = "ifcmerge-forward" try: # NOTE this is calling the git binary in a subprocess repo.git.merge(branch) except git.exc.GitCommandError: # merge is expected to fail, run ifcmerge try: - repo.git.mergetool(tool="ifcmerge") + repo.git.mergetool(tool=mergetool) except git.exc.GitCommandError as exc: message = re.sub("( stderr: '|')", "", exc.stderr) # ifcmerge failed, rollback