feat(git): allow cherry-pick to suppress tag altogether

This commit is contained in:
Elliot Nelson
2022-09-18 09:22:35 -04:00
parent 4f96116c43
commit 4e4b5ccf8d
4 changed files with 29 additions and 2 deletions

View File

@@ -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(
`

View File

@@ -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:

View File

@@ -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:<id>') {
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;

View File

@@ -117,7 +117,7 @@ branchStatement
;
cherryPickStatement
: CHERRY_PICK COMMIT_ID STR {yy.cherryPick($3, '', '')}
: CHERRY_PICK COMMIT_ID STR {yy.cherryPick($3, '', 'cherry-pick:<id>')}
| CHERRY_PICK COMMIT_ID STR COMMIT_TAG STR {yy.cherryPick($3, '', $5)}
| CHERRY_PICK COMMIT_TAG STR COMMIT_ID STR {yy.cherryPick($5, '', $3)}
;