{"record":{"id":"97b5ca28ae844c4b","repo":"mermaid-js/mermaid","slug":"cannot-merge-branch-otherbranch-into-itself","errorCode":null,"errorMessage":"Cannot merge branch '${otherBranch}' into itself.","messagePattern":"Cannot merge branch '(.+?)' into itself\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/git/gitGraphAst.ts","lineNumber":171,"sourceCode":"  let otherBranch = mergeDB.branch;\n  let customId = mergeDB.id;\n  const overrideType = mergeDB.type;\n  const customTags = mergeDB.tags;\n  const config = getConfig();\n  otherBranch = common.sanitizeText(otherBranch, config);\n  if (customId) {\n    customId = common.sanitizeText(customId, config);\n  }\n  const currentBranchCheck = state.records.branches.get(state.records.currBranch);\n  const otherBranchCheck = state.records.branches.get(otherBranch);\n  const currentCommit = currentBranchCheck\n    ? state.records.commits.get(currentBranchCheck)\n    : undefined;\n  const otherCommit: Commit | undefined = otherBranchCheck\n    ? state.records.commits.get(otherBranchCheck)\n    : undefined;\n  if (currentCommit && otherCommit && currentCommit.branch === otherBranch) {\n    throw new Error(`Cannot merge branch '${otherBranch}' into itself.`);\n  }\n  if (state.records.currBranch === otherBranch) {\n    const error: any = new Error('Incorrect usage of \"merge\". Cannot merge a branch to itself');\n    error.hash = {\n      text: `merge ${otherBranch}`,\n      token: `merge ${otherBranch}`,\n      expected: ['branch abc'],\n    };\n    throw error;\n  }\n  if (currentCommit === undefined || !currentCommit) {\n    const error: any = new Error(\n      `Incorrect usage of \"merge\". Current branch (${state.records.currBranch})has no commits`\n    );\n    error.hash = {\n      text: `merge ${otherBranch}`,\n      token: `merge ${otherBranch}`,\n      expected: ['commit'],","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/git/gitGraphAst.ts#L153-L189","documentation":"Error \"Cannot merge branch '${otherBranch}' into itself.\" thrown in mermaid-js/mermaid.","triggerScenarios":"Thrown at packages/mermaid/src/diagrams/git/gitGraphAst.ts:171 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}