From de89355a49a7832e672389fe977b572633acca35 Mon Sep 17 00:00:00 2001 From: JingyuMarcelLee Date: Wed, 20 Mar 2024 01:20:20 -0400 Subject: [PATCH 1/2] Recommitted Changed due to polluted branch --- .../integration/rendering/gitGraph.spec.js | 446 ++++++++++++++++++ demos/git.html | 182 +++++++ docs/syntax/gitgraph.md | 42 +- .../src/diagrams/git/gitGraphParser.spec.js | 14 +- .../src/diagrams/git/gitGraphRenderer.js | 217 +++++++-- .../src/diagrams/git/parser/gitGraph.jison | 3 +- packages/mermaid/src/docs/syntax/gitgraph.md | 27 +- 7 files changed, 889 insertions(+), 42 deletions(-) diff --git a/cypress/integration/rendering/gitGraph.spec.js b/cypress/integration/rendering/gitGraph.spec.js index 2184fecf88..4e8f7fdcac 100644 --- a/cypress/integration/rendering/gitGraph.spec.js +++ b/cypress/integration/rendering/gitGraph.spec.js @@ -1013,4 +1013,450 @@ gitGraph TB: { gitGraph: { parallelCommits: true } } ); }); + describe('Git-Graph Bottom-to-Top Orientation Tests', () => { + it('50: should render a simple gitgraph with commit on main branch | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "1" + commit id: "2" + commit id: "3" + `, + {} + ); + }); + it('51: should render a simple gitgraph with commit on main branch with Id | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "One" + commit id: "Two" + commit id: "Three" + `, + {} + ); + }); + it('52: should render a simple gitgraph with different commitTypes on main branch | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "Normal Commit" + commit id: "Reverse Commit" type: REVERSE + commit id: "Highlight Commit" type: HIGHLIGHT + `, + {} + ); + }); + it('53: should render a simple gitgraph with tags commitTypes on main branch | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "Normal Commit with tag" tag: "v1.0.0" + commit id: "Reverse Commit with tag" type: REVERSE tag: "RC_1" + commit id: "Highlight Commit" type: HIGHLIGHT tag: "8.8.4" + `, + {} + ); + }); + it('54: should render a simple gitgraph with two branches | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "1" + commit id: "2" + branch develop + checkout develop + commit id: "3" + commit id: "4" + checkout main + commit id: "5" + commit id: "6" + `, + {} + ); + }); + it('55: should render a simple gitgraph with two branches and merge commit | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "1" + commit id: "2" + branch develop + checkout develop + commit id: "3" + commit id: "4" + checkout main + merge develop + commit id: "5" + commit id: "6" + `, + {} + ); + }); + it('56: should render a simple gitgraph with three branches and tagged merge commit | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "1" + commit id: "2" + branch nice_feature + checkout nice_feature + commit id: "3" + checkout main + commit id: "4" + checkout nice_feature + branch very_nice_feature + checkout very_nice_feature + commit id: "5" + checkout main + commit id: "6" + checkout nice_feature + commit id: "7" + checkout main + merge nice_feature id: "12345" tag: "my merge commit" + checkout very_nice_feature + commit id: "8" + checkout main + commit id: "9" + `, + {} + ); + }); + it('57: should render a simple gitgraph with more than 8 branches & overriding variables | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': { + 'gitBranchLabel0': '#ffffff', + 'gitBranchLabel1': '#ffffff', + 'gitBranchLabel2': '#ffffff', + 'gitBranchLabel3': '#ffffff', + 'gitBranchLabel4': '#ffffff', + 'gitBranchLabel5': '#ffffff', + 'gitBranchLabel6': '#ffffff', + 'gitBranchLabel7': '#ffffff', + } } }%% + gitGraph BT: + checkout main + branch branch1 + branch branch2 + branch branch3 + branch branch4 + branch branch5 + branch branch6 + branch branch7 + branch branch8 + branch branch9 + checkout branch1 + commit id: "1" + `, + {} + ); + }); + it('58: should render a simple gitgraph with rotated labels | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'gitGraph': { + 'rotateCommitLabel': true + } } }%% + gitGraph BT: + commit id: "75f7219e83b321cd3fdde7dcf83bc7c1000a6828" + commit id: "0db4784daf82736dec4569e0dc92980d328c1f2e" + commit id: "7067e9973f9eaa6cd4a4b723c506d1eab598e83e" + commit id: "66972321ad6c199013b5b31f03b3a86fa3f9817d" + `, + {} + ); + }); + it('59: should render a simple gitgraph with horizontal labels | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'gitGraph': { + 'rotateCommitLabel': false + } } }%% + gitGraph BT: + commit id: "Alpha" + commit id: "Beta" + commit id: "Gamma" + commit id: "Delta" + `, + {} + ); + }); + it('60: should render a simple gitgraph with cherry pick commit | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + ` + gitGraph BT: + commit id: "ZERO" + branch develop + commit id:"A" + checkout main + commit id:"ONE" + checkout develop + commit id:"B" + checkout main + commit id:"TWO" + cherry-pick id:"A" + commit id:"THREE" + checkout develop + commit id:"C" + `, + {} + ); + }); + it('61: should render a gitgraph with cherry pick commit with custom tag | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + ` + gitGraph BT: + commit id: "ZERO" + branch develop + commit id:"A" + checkout main + commit id:"ONE" + checkout develop + commit id:"B" + checkout main + commit id:"TWO" + cherry-pick id:"A" tag: "snapshot" + commit id:"THREE" + checkout develop + commit id:"C" + `, + {} + ); + }); + it('62: should render a gitgraph with cherry pick commit with no tag | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + ` + gitGraph BT: + commit id: "ZERO" + branch develop + commit id:"A" + checkout main + commit id:"ONE" + checkout develop + commit id:"B" + checkout main + commit id:"TWO" + cherry-pick id:"A" tag: "" + commit id:"THREE" + checkout develop + commit id:"C" + `, + {} + ); + }); + it('63: should render a simple gitgraph with two cherry pick commit | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + ` + gitGraph BT: + commit id: "ZERO" + branch develop + commit id:"A" + checkout main + commit id:"ONE" + checkout develop + commit id:"B" + branch featureA + commit id:"FIX" + commit id: "FIX-2" + checkout main + commit id:"TWO" + cherry-pick id:"A" + commit id:"THREE" + cherry-pick id:"FIX" + checkout develop + commit id:"C" + merge featureA + `, + {} + ); + }); + it('64: should render commits for more than 8 branches | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + ` + gitGraph BT: + checkout main + %% Make sure to manually set the ID of all commits, for consistent visual tests + commit id: "1-abcdefg" + checkout main + branch branch1 + commit id: "2-abcdefg" + checkout main + merge branch1 + branch branch2 + commit id: "3-abcdefg" + checkout main + merge branch2 + branch branch3 + commit id: "4-abcdefg" + checkout main + merge branch3 + branch branch4 + commit id: "5-abcdefg" + checkout main + merge branch4 + branch branch5 + commit id: "6-abcdefg" + checkout main + merge branch5 + branch branch6 + commit id: "7-abcdefg" + checkout main + merge branch6 + branch branch7 + commit id: "8-abcdefg" + checkout main + merge branch7 + branch branch8 + commit id: "9-abcdefg" + checkout main + merge branch8 + branch branch9 + commit id: "10-abcdefg" + `, + {} + ); + }); + it('65: should render a simple gitgraph with three branches,custom merge commit id,tag,type | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id: "1" + commit id: "2" + branch nice_feature + checkout nice_feature + commit id: "3" + checkout main + commit id: "4" + checkout nice_feature + branch very_nice_feature + checkout very_nice_feature + commit id: "5" + checkout main + commit id: "6" + checkout nice_feature + commit id: "7" + checkout main + merge nice_feature id: "customID" tag: "customTag" type: REVERSE + checkout very_nice_feature + commit id: "8" + checkout main + commit id: "9" + `, + {} + ); + }); + it('66: should render a simple gitgraph with a title | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `--- + title: simple gitGraph + --- + gitGraph BT: + commit id: "1-abcdefg" + `, + {} + ); + }); + it('67: should render a simple gitgraph overlapping commits | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id:"s1" + commit id:"s2" + branch branch1 + commit id:"s3" + commit id:"s4" + checkout main + commit id:"s5" + checkout branch1 + commit id:"s6" + commit id:"s7" + merge main + `, + {} + ); + }); + it('68: should render a simple gitgraph with two branches from same commit | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id:"1-abcdefg" + commit id:"2-abcdefg" + branch feature-001 + commit id:"3-abcdefg" + commit id:"4-abcdefg" + checkout main + branch feature-002 + commit id:"5-abcdefg" + checkout feature-001 + merge feature-002 + `, + {} + ); + }); + it('69: should render GitGraph with branch that is not used immediately | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id:"1-abcdefg" + branch x + checkout main + commit id:"2-abcdefg" + checkout x + commit id:"3-abcdefg" + checkout main + merge x + `, + {} + ); + }); + it('70: should render GitGraph with branch and sub-branch neither of which used immediately | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id:"1-abcdefg" + branch x + checkout main + commit id:"2-abcdefg" + checkout x + commit id:"3-abcdefg" + checkout main + merge x + checkout x + branch y + checkout x + commit id:"4-abcdefg" + checkout y + commit id:"5-abcdefg" + checkout x + merge y + `, + {} + ); + }); + it('71: should render GitGraph with parallel commits | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + commit id:"1-abcdefg" + commit id:"2-abcdefg" + branch develop + commit id:"3-abcdefg" + commit id:"4-abcdefg" + checkout main + branch feature + commit id:"5-abcdefg" + commit id:"6-abcdefg" + checkout main + commit id:"7-abcdefg" + commit id:"8-abcdefg" + `, + { gitGraph: { parallelCommits: true } } + ); + }); + it('72: should render GitGraph with unconnected branches and parallel commits | Vertical Branch - Bottom-to-top', () => { + imgSnapshotTest( + `gitGraph BT: + branch dev + branch v2 + branch feat + commit id:"1-abcdefg" + commit id:"2-abcdefg" + checkout main + commit id:"3-abcdefg" + checkout dev + commit id:"4-abcdefg" + checkout v2 + commit id:"5-abcdefg" + checkout main + commit id:"6-abcdefg" + `, + { gitGraph: { parallelCommits: true } } + ); + }); + }); }); diff --git a/demos/git.html b/demos/git.html index 92e0e68635..697163ac34 100644 --- a/demos/git.html +++ b/demos/git.html @@ -40,6 +40,19 @@

Simple "branch and merge" graph

checkout main merge newbranch +
+      ---
+      title: Simple "branch and merge" (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch newbranch
+      checkout newbranch
+      commit
+      checkout main
+      merge newbranch
+      

Continuous development graph

     ---
@@ -73,6 +86,23 @@ 

Continuous development graph

checkout main merge develop
+
+      ---
+      title: Continuous development (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch develop
+      checkout develop
+      commit
+      checkout main
+      merge develop
+      checkout develop
+      commit
+      checkout main
+      merge develop
+      

Merge feature to advanced main graph

     ---
@@ -100,6 +130,20 @@ 

Merge feature to advanced main graph

commit merge newbranch
+
+      ---
+      title: Merge feature to advanced main (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch newbranch
+      checkout newbranch
+      commit
+      checkout main
+      commit
+      merge newbranch
+      

Two-way merges

     ---
@@ -137,6 +181,25 @@ 

Two-way merges

checkout main merge develop
+
+      ---
+      title: Two-way merges (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch develop
+      checkout develop
+      commit
+      checkout main
+      merge develop
+      commit
+      checkout develop
+      merge main
+      commit
+      checkout main
+      merge develop
+      

Cherry-pick from branch graph

     ---
@@ -170,6 +233,22 @@ 

Cherry-pick from branch graph

checkout main cherry-pick id: "Pick me"
+
+      ---
+      title: Cherry-pick from branch (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch newbranch
+      checkout newbranch
+      commit id: "Pick me"
+      checkout main
+      commit
+      checkout newbranch
+      commit
+      checkout main
+      cherry-pick id: "Pick me"
+    

Cherry-pick from main graph

     ---
@@ -199,6 +278,21 @@ 

Cherry-pick from main graph

commit cherry-pick id: "A"
+
+      ---
+      title: Cherry-pick from main (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch develop
+      commit
+      checkout main
+      commit id:"A"
+      checkout develop
+      commit
+      cherry-pick id: "A"
+      

Cherry-pick then merge graph

     ---
@@ -234,6 +328,24 @@ 

Cherry-pick then merge graph

cherry-pick id: "Pick me" merge newbranch
+
+      ---
+      title: Cherry-pick then merge (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch newbranch
+      checkout newbranch
+      commit id: "Pick me"
+      checkout main
+      commit
+      checkout newbranch
+      commit
+      checkout main
+      cherry-pick id: "Pick me"
+      merge newbranch
+      

Merge from main onto undeveloped branch graph

     ---
@@ -261,6 +373,20 @@ 

Merge from main onto undeveloped branch graph

checkout develop merge main
+
+      ---
+      title: Merge from main onto undeveloped branch (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch develop
+      commit
+      checkout main
+      commit
+      checkout develop
+      merge main
+      

Merge from main onto developed branch graph

     ---
@@ -290,6 +416,21 @@ 

Merge from main onto developed branch graph

commit merge main
+
+      ---
+      title: Merge from main onto developed branch (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      branch develop
+      commit
+      checkout main
+      commit
+      checkout develop
+      commit
+      merge main
+      

Two branches from same commit graph

     ---
@@ -323,6 +464,23 @@ 

Two branches from same commit graph

checkout feature-001 merge feature-002
+
+      ---
+      title: Two branches from same commit (bottom-to-top)
+      ---
+      gitGraph BT:
+      commit
+      commit
+      branch feature-001
+      commit
+      commit
+      checkout main
+      branch feature-002
+      commit
+      checkout feature-001
+      merge feature-002
+      

Three branches and a cherry-pick from each graph

     ---
@@ -372,6 +530,30 @@ 

Three branches and a cherry-pick from each graph

commit id:"C" merge featureA
+
+    ---
+    title: Three branches and a cherry-pick from each (bottom-to-top)
+    ---
+    gitGraph BT:
+    commit id: "ZERO"
+    branch develop
+    commit id:"A"
+    checkout main
+    commit id:"ONE"
+    checkout develop
+    commit id:"B"
+    branch featureA
+    commit id:"FIX"
+    commit id: "FIX-2"
+    checkout main
+    commit id:"TWO"
+    cherry-pick id:"A"
+    commit id:"THREE"
+    cherry-pick id:"FIX"
+    checkout develop
+    commit id:"C"
+    merge featureA
+