From 9f8457d249351d685f54edb034c54f7482bc3d1c Mon Sep 17 00:00:00 2001 From: Guy Pursey Date: Thu, 12 Oct 2023 21:36:17 +0100 Subject: [PATCH] GitGraph: Rewrote overlap fn to make main branch exception to rule. --- .../mermaid/src/diagrams/git/gitGraphRenderer.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js index c1a11f2b4..2c737ec10 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphRenderer.js +++ b/packages/mermaid/src/diagrams/git/gitGraphRenderer.js @@ -352,12 +352,16 @@ const drawCommits = (svg, commits, modifyGraph) => { * and commitB's x-position */ const hasOverlappingCommits = (commitA, commitB, allCommits) => - Object.values(allCommits).some( - (commitX) => - (commitX.branch === commitA.branch || commitX.branch === commitB.branch) && - commitX.seq > commitA.seq && - commitX.seq < commitB.seq - ); + Object.values(allCommits).some((commitX) => { + const isOnSourceBranch = (x) => x.branch === commitA.branch; + const isOnTargetBranch = (x) => x.branch === commitB.branch; + const isBetweenCommits = (x) => x.seq > commitA.seq && x.seq < commitB.seq; + const isTargetMain = (x) => x.branch === getConfig().gitGraph.mainBranchName; + return ( + (isOnSourceBranch(commitX) || (isOnTargetBranch(commitX) && !isTargetMain(commitX))) && + isBetweenCommits(commitX) + ); + }); /** * This function find a lane in the y-axis that is not overlapping with any other lanes. This is