From 31a1de156685539008ffe666ad1ce1ca3435bb71 Mon Sep 17 00:00:00 2001 From: RounakJoshi09 Date: Mon, 4 Dec 2023 00:28:01 +0530 Subject: [PATCH] Condition of Parent Id Without Merge Commit Added --- .../mermaid/src/diagrams/git/gitGraphAst.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/mermaid/src/diagrams/git/gitGraphAst.js b/packages/mermaid/src/diagrams/git/gitGraphAst.js index 56f48c6d39..3d34283b38 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphAst.js +++ b/packages/mermaid/src/diagrams/git/gitGraphAst.js @@ -277,19 +277,17 @@ export const cherryPick = function (sourceId, targetId, tag, parentCommitId) { } let sourceCommit = commits[sourceId]; let sourceCommitBranch = sourceCommit.branch; - if (sourceCommit.type === commitType.MERGE) { - if (!parentCommitId) { - let error = new Error( - 'Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified.' - ); - throw error; - } - if (!(Array.isArray(sourceCommit.parents) && sourceCommit.parents.includes(parentCommitId))) { - let error = new Error( - 'Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit.' - ); - throw error; - } + if (!(Array.isArray(sourceCommit.parents) && sourceCommit.parents.includes(parentCommitId))) { + let error = new Error( + 'Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit.' + ); + throw error; + } + if (sourceCommit.type === commitType.MERGE && !parentCommitId) { + let error = new Error( + 'Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified.' + ); + throw error; } if (!targetId || commits[targetId] === undefined) { // cherry-pick source commit to current branch