diff --git a/cypress/integration/rendering/gitGraph.spec.js b/cypress/integration/rendering/gitGraph.spec.js index 3331f0d33..afb39b62e 100644 --- a/cypress/integration/rendering/gitGraph.spec.js +++ b/cypress/integration/rendering/gitGraph.spec.js @@ -201,6 +201,27 @@ describe('Git Graph diagram', () => { {} ); }); + it('11: should render a gitgraph with cherry pick commit with no tag', () => { + imgSnapshotTest( + ` + gitGraph + 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('11: should render a simple gitgraph with two cherry pick commit', () => { imgSnapshotTest( ` diff --git a/docs/gitgraph.md b/docs/gitgraph.md index bdf2f3a5a..863681085 100644 --- a/docs/gitgraph.md +++ b/docs/gitgraph.md @@ -429,6 +429,8 @@ By default, the cherry-picked commit from commit with id `A` will be labeled `ch commit id:"C" ``` +To suppress the tag entirely, use `tag:""` (empty string). + ## Gitgraph specific configuration options In Mermaid, you have the option to configure the gitgraph diagram. You can configure the following options: diff --git a/src/diagrams/git/gitGraphAst.js b/src/diagrams/git/gitGraphAst.js index e222a046b..3a6260d4f 100644 --- a/src/diagrams/git/gitGraphAst.js +++ b/src/diagrams/git/gitGraphAst.js @@ -262,6 +262,10 @@ export const cherryPick = function (sourceId, targetId, tag) { log.debug('Entering cherryPick:', sourceId, targetId, tag); sourceId = common.sanitizeText(sourceId, configApi.getConfig()); targetId = common.sanitizeText(targetId, configApi.getConfig()); + + if (tag === 'cherry-pick:') { + tag = 'cherry-pick:' + sourceCommit.id; + } tag = common.sanitizeText(tag, configApi.getConfig()); if (!sourceId || typeof commits[sourceId] === 'undefined') { @@ -330,7 +334,7 @@ export const cherryPick = function (sourceId, targetId, tag) { parents: [head == null ? null : head.id, sourceCommit.id], branch: curBranch, type: commitType.CHERRY_PICK, - tag: tag ? tag : 'cherry-pick:' + sourceCommit.id, + tag: tag, }; head = commit; commits[commit.id] = commit; diff --git a/src/diagrams/git/parser/gitGraph.jison b/src/diagrams/git/parser/gitGraph.jison index 18eca1f08..057186dee 100644 --- a/src/diagrams/git/parser/gitGraph.jison +++ b/src/diagrams/git/parser/gitGraph.jison @@ -117,7 +117,7 @@ branchStatement ; cherryPickStatement - : CHERRY_PICK COMMIT_ID STR {yy.cherryPick($3, '', '')} + : CHERRY_PICK COMMIT_ID STR {yy.cherryPick($3, '', 'cherry-pick:')} | CHERRY_PICK COMMIT_ID STR COMMIT_TAG STR {yy.cherryPick($3, '', $5)} | CHERRY_PICK COMMIT_TAG STR COMMIT_ID STR {yy.cherryPick($5, '', $3)} ;