mermaid-js / mermaid-live-editor

Edit, preview and share mermaid charts/diagrams. New implementation of the live editor.
https://mermaid.live
MIT License
4k stars 596 forks source link

Autosync fails supriously when mainBranchName is not main #1313

Closed codeinred closed 6 months ago

codeinred commented 10 months ago

Describe the bug

Attempting to check out the main branch results in a spurious error. For example, if mainBranchName is configured to HEAD, and the diagram attempts to check it out, the following error will occur:

Error: Trying to checkout branch which is not yet created. (Help try using "branch HEAD")

Note that this error occurs regardless of a particular choice of mainBranchName.

This error is suprious. The following actions make the error go away:

Note that neither of these actions fix the issue in downstream projects like vscode-markdown-mermaid, so vscode-markdown-mermaid will always emit an error with these diagrams.

Corresponding graph:

%%{
    init: {
        'theme': 'base',
        'gitGraph': {
            'showCommitLabel': false,
            'mainBranchName': 'HEAD'
        }
    }
}%%

gitGraph:
    commit
    commit
    branch feature
    commit
    checkout HEAD
    commit

Related Issue

See this issue in vscode-markdown-mermaid: https://github.com/mjbvz/vscode-markdown-mermaid/issues/214

Steps To Reproduce

Link to Live Editor:

  1. Go to the live editor in a private window
  2. Copy and paste the following code:
    
    %%{
    init: {
        'theme': 'base',
        'gitGraph': {
            'showCommitLabel': false,
            'mainBranchName': 'HEAD'
        }
    }
    }%%

gitGraph: commit commit branch feature commit checkout HEAD commit


3. Observe that there's an error

## Expected behavior
The diagram should render correctly in the live editor, without emitting an error, because the `HEAD` branch exists.

## Screenshots

Error in live editor after copy-pasting the code for the diagram:

![image](https://github.com/mermaid-js/mermaid-live-editor/assets/36810712/4e50ec86-a5f4-4a0e-9ba5-9c05f7dc942b)

Related error as it appears in downstream project vscode-markdown-mermaid:

![image](https://github.com/mermaid-js/mermaid-live-editor/assets/36810712/f800ab88-7919-4610-aebc-ad6e1e03d2b3)
codeinred commented 10 months ago

Additional related issues: https://github.com/mermaid-js/mermaid/issues/4141

github-actions[bot] commented 7 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days