mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
72.77k stars 6.64k forks source link

gitGraph: Cannot merge main into a production branch that has no prior commits in it #5898

Open threepistons opened 2 months ago

threepistons commented 2 months ago

Description

I'm sure that this syntax used to work, because I would not have allowed a broken diagram into my documentation back in January and my diagram is broken now, so I'm raising this as a regression bug.

A common use case for Git is to have a main (or master, or develop) branch that is merged at intervals into a production (or release, or deployment) branch. A simple example of gitGraph to display this would be as follows:

gitGraph
    commit id: "Initial commit, will be released in the production branch about to be created."
    branch production
    merge main
    checkout main
    commit id: "Dave adds a config file"
    branch 01_topic
    checkout 01_topic
    commit id: "Helen adds a feature"
    checkout main
    commit id: "Dave adds another config file"
    commit id: "Tom adds a config file"
    checkout 01_topic
    commit id: "Helen adds more of the feature"
    checkout main
    merge 01_topic id: "Helen merges the feature into main"
    commit id: "Claire adds a config file"
    commit id: "Dave adds yet another config file"
    checkout production
    merge main id: "Helen merges main to production"

In the development version of the Live Editor and in GitHub, I get "Error: Cannot merge branch 'main' into itself."

What I expect is a diagram that looks something like: puppet-r10k-flow-for-mermaid-bug-report

Steps to reproduce

  1. Go to https://develop.git.mermaid.live/
  2. Paste the code in the code snippet.
  3. See the error message instead of a diagram.

Or go to https://develop.git.mermaid.live/edit#pako:eNqdU01PwzAM_StWzhWCa69MAg6c4FgJuYnbRiRx5aagadp_x11X2KZtCJpL82y_569sjGVHpjStzw-CfVcl0M9yjD6DdyVU5in57DHswQI-fQhQEwgFwoEc-AS5I-iF3Wiz5wS1YLIdYM1jhsyTtxXCTO6mMrPE3uUnaIYjSUsQUTln9Y5Cv8TYjuz7RDnZz2S6wg8CdG4AVENqfAuND3QieXv3lrn39oTzBD7kfdRK00LcaB2j0D9ySqxtknOZHUW8crxSxB_zjSwE3OwG9Hvmc_cX5iO2nWk45NG562gjDpnkbCH3Ab1cG8iFRq0pX23Wkvfl3an0mMIooDen672ZPCoTuK3MJOaoHvW3mGFVirQ3oLxPQlsNxzHzyzpZU2YZqTDCY9uZssEw6G3snS70ymMrGL9Rcj6zPM-Pave2tl_0yCHc for one I made earlier.

Screenshots

No response

Code Sample

gitGraph
    commit id: "Initial commit, will be released in the production branch about to be created."
    branch production
    merge main
    checkout main
    commit id: "Dave adds a config file"
    branch 01_topic
    checkout 01_topic
    commit id: "Helen adds a feature"
    checkout main
    commit id: "Dave adds another config file"
    commit id: "Tom adds a config file"
    checkout 01_topic
    commit id: "Helen adds more of the feature"
    checkout main
    merge 01_topic id: "Helen merges the feature into main"
    commit id: "Claire adds a config file"
    commit id: "Dave adds yet another config file"
    checkout production
    merge main id: "Helen merges main to production"

Setup

Suggested Solutions

No response

Additional Context

No response

EBrookeLoreto commented 2 months ago

I've hit this problem too after re-publishing my site.

mermaid.min.js:710  Uncaught (in promise) Error: Cannot merge branch 'master' into itself.
    at Object.merge (mermaid.min.js:710:3360)
    at Merge (mermaid.min.js:710:9334)
    at parseStatement (mermaid.min.js:710:9471)
    at populate (mermaid.min.js:710:9200)
    at Object.parse (mermaid.min.js:710:10035)
    at async Diagram.fromText (mermaid.min.js:2108:248)
    at async Object.render (mermaid.min.js:2146:1187)

This worked previously but I'm not 100% which version of Mermaid I was using. I'm using a MkDocs site.

rbroth commented 3 weeks ago

I'm also affected.

It seems that in previous versions it was possible to merge another branch so that only a merge commit was created, but with this bug it's necessary to create a "normal" commit first.

This used to work:

gitGraph
    commit id: " "
    branch branch2
    checkout main
    commit id: " "
    checkout branch2
    merge main
gitGraph
    commit id: " "
    branch branch2
    checkout main
    commit id: " "
    checkout branch2
    merge main

Now this is necessary:

gitGraph
    commit id: " "
    branch branch2
    checkout main
    commit id: " "
    checkout branch2
    commit id: "dummy commit"
    merge main
gitGraph
    commit id: " "
    branch branch2
    checkout main
    commit id: " "
    checkout branch2
    commit id: "dummy commit"
    merge main

Edit: Confirm broken in mermaid version 10.7.0