From 5460bc0a0c46dcd6dda345357d7ac418c9c20a74 Mon Sep 17 00:00:00 2001 From: Austin Fulbright Date: Wed, 24 Jul 2024 07:13:10 -0400 Subject: [PATCH] fixed checkout branch with no commits --- packages/mermaid/src/diagrams/git/gitGraphAst.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/mermaid/src/diagrams/git/gitGraphAst.ts b/packages/mermaid/src/diagrams/git/gitGraphAst.ts index b04e78d8c5..9a26d32f7d 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphAst.ts +++ b/packages/mermaid/src/diagrams/git/gitGraphAst.ts @@ -399,14 +399,11 @@ export const checkout = function (branch: string) { } else { curBranch = branch; const id = branches.get(curBranch); - - if (id === null || id === undefined) { - throw new Error('Branch ' + branch + ' has no commits'); - } - if (commits.get(id) === undefined) { - throw new Error('Branch ' + branch + ' has no commits'); + if (id === undefined || !id) { + head = null; + } else { + head = commits.get(id) ?? null; } - head = commits.get(id) ?? null; } };