Skip to content

Commit

Permalink
Condition of Parent Id Without Merge Commit Added
Browse files Browse the repository at this point in the history
  • Loading branch information
RounakJoshi09 authored Dec 3, 2023
1 parent c6bf908 commit 31a1de1
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/mermaid/src/diagrams/git/gitGraphAst.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 31a1de1

Please sign in to comment.