mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Merge pull request #3726 from gibson042/gh-3725-gitgraph-quoted-branch-names
fix(git): Support quoted branch names
This commit is contained in:
commit
c1529bb7fc
@ -165,7 +165,7 @@ In this example, we have given custom tags to the commits. Also, see how we have
|
|||||||
|
|
||||||
### Create a new branch
|
### Create a new branch
|
||||||
|
|
||||||
In Mermaid, in-order to create a new branch, you make use of the `branch` keyword. You also need to provide a name of the new branch. The name has to be unique and cannot be that of an existing branch. Usage example: `branch develop`
|
In Mermaid, in-order to create a new branch, you make use of the `branch` keyword. You also need to provide a name of the new branch. The name has to be unique and cannot be that of an existing branch. A branch name that could be confused for a keyword must be quoted within `""`. Usage examples: `branch develop`, `branch "cherry-pick"`
|
||||||
|
|
||||||
When Mermaid, reads the `branch` keyword, it creates a new branch and sets it as the current branch. Equivalent to you creating a new branch and checking it out in Git world.
|
When Mermaid, reads the `branch` keyword, it creates a new branch and sets it as the current branch. Equivalent to you creating a new branch and checking it out in Git world.
|
||||||
|
|
||||||
|
@ -334,6 +334,31 @@ describe('when parsing a gitGraph', function () {
|
|||||||
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow quoted branch names', function () {
|
||||||
|
const str = `gitGraph:
|
||||||
|
commit
|
||||||
|
branch "branch"
|
||||||
|
checkout "branch"
|
||||||
|
commit
|
||||||
|
checkout main
|
||||||
|
merge "branch"
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const commits = parser.yy.getCommits();
|
||||||
|
expect(Object.keys(commits).length).toBe(3);
|
||||||
|
expect(parser.yy.getCurrentBranch()).toBe('main');
|
||||||
|
expect(parser.yy.getDirection()).toBe('LR');
|
||||||
|
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
|
||||||
|
const commit1 = Object.keys(commits)[0];
|
||||||
|
const commit2 = Object.keys(commits)[1];
|
||||||
|
const commit3 = Object.keys(commits)[2];
|
||||||
|
expect(commits[commit1].branch).toBe('main');
|
||||||
|
expect(commits[commit2].branch).toBe('branch');
|
||||||
|
expect(commits[commit3].branch).toBe('main');
|
||||||
|
expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([{ name: 'main' }, { name: 'branch' }]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should allow _-./ characters in branch names', function () {
|
it('should allow _-./ characters in branch names', function () {
|
||||||
const str = `gitGraph:
|
const str = `gitGraph:
|
||||||
commit
|
commit
|
||||||
|
@ -109,12 +109,12 @@ statement
|
|||||||
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
|
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
|
||||||
| acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); } | section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
| acc_descr_multiline_value { $$=$1.trim();yy.setAccDescription($$); } | section {yy.addSection($1.substr(8));$$=$1.substr(8);}
|
||||||
| branchStatement
|
| branchStatement
|
||||||
| CHECKOUT ID {yy.checkout($2)}
|
| CHECKOUT ref {yy.checkout($2)}
|
||||||
// | RESET reset_arg {yy.reset($2)}
|
// | RESET reset_arg {yy.reset($2)}
|
||||||
;
|
;
|
||||||
branchStatement
|
branchStatement
|
||||||
: BRANCH ID {yy.branch($2)}
|
: BRANCH ref {yy.branch($2)}
|
||||||
| BRANCH ID ORDER NUM {yy.branch($2, $4)}
|
| BRANCH ref ORDER NUM {yy.branch($2, $4)}
|
||||||
;
|
;
|
||||||
|
|
||||||
cherryPickStatement
|
cherryPickStatement
|
||||||
@ -126,22 +126,22 @@ cherryPickStatement
|
|||||||
;
|
;
|
||||||
|
|
||||||
mergeStatement
|
mergeStatement
|
||||||
: MERGE ID {yy.merge($2,'','','')}
|
: MERGE ref {yy.merge($2,'','','')}
|
||||||
| MERGE ID COMMIT_ID STR {yy.merge($2, $4,'','')}
|
| MERGE ref COMMIT_ID STR {yy.merge($2, $4,'','')}
|
||||||
| MERGE ID COMMIT_TYPE commitType {yy.merge($2,'', $4,'')}
|
| MERGE ref COMMIT_TYPE commitType {yy.merge($2,'', $4,'')}
|
||||||
| MERGE ID COMMIT_TAG STR {yy.merge($2, '','',$4)}
|
| MERGE ref COMMIT_TAG STR {yy.merge($2, '','',$4)}
|
||||||
| MERGE ID COMMIT_TAG STR COMMIT_ID STR {yy.merge($2, $6,'', $4)}
|
| MERGE ref COMMIT_TAG STR COMMIT_ID STR {yy.merge($2, $6,'', $4)}
|
||||||
| MERGE ID COMMIT_TAG STR COMMIT_TYPE commitType {yy.merge($2, '',$6, $4)}
|
| MERGE ref COMMIT_TAG STR COMMIT_TYPE commitType {yy.merge($2, '',$6, $4)}
|
||||||
| MERGE ID COMMIT_TYPE commitType COMMIT_TAG STR {yy.merge($2, '',$4, $6)}
|
| MERGE ref COMMIT_TYPE commitType COMMIT_TAG STR {yy.merge($2, '',$4, $6)}
|
||||||
| MERGE ID COMMIT_ID STR COMMIT_TYPE commitType {yy.merge($2, $4, $6, '')}
|
| MERGE ref COMMIT_ID STR COMMIT_TYPE commitType {yy.merge($2, $4, $6, '')}
|
||||||
| MERGE ID COMMIT_ID STR COMMIT_TAG STR {yy.merge($2, $4, '', $6)}
|
| MERGE ref COMMIT_ID STR COMMIT_TAG STR {yy.merge($2, $4, '', $6)}
|
||||||
| MERGE ID COMMIT_TYPE commitType COMMIT_ID STR {yy.merge($2, $6,$4, '')}
|
| MERGE ref COMMIT_TYPE commitType COMMIT_ID STR {yy.merge($2, $6,$4, '')}
|
||||||
| MERGE ID COMMIT_ID STR COMMIT_TYPE commitType COMMIT_TAG STR {yy.merge($2, $4, $6, $8)}
|
| MERGE ref COMMIT_ID STR COMMIT_TYPE commitType COMMIT_TAG STR {yy.merge($2, $4, $6, $8)}
|
||||||
| MERGE ID COMMIT_TYPE commitType COMMIT_TAG STR COMMIT_ID STR {yy.merge($2, $8, $4, $6)}
|
| MERGE ref COMMIT_TYPE commitType COMMIT_TAG STR COMMIT_ID STR {yy.merge($2, $8, $4, $6)}
|
||||||
| MERGE ID COMMIT_ID STR COMMIT_TAG STR COMMIT_TYPE commitType {yy.merge($2, $4, $8, $6)}
|
| MERGE ref COMMIT_ID STR COMMIT_TAG STR COMMIT_TYPE commitType {yy.merge($2, $4, $8, $6)}
|
||||||
| MERGE ID COMMIT_TYPE commitType COMMIT_ID STR COMMIT_TAG STR {yy.merge($2, $6, $4, $8)}
|
| MERGE ref COMMIT_TYPE commitType COMMIT_ID STR COMMIT_TAG STR {yy.merge($2, $6, $4, $8)}
|
||||||
| MERGE ID COMMIT_TAG STR COMMIT_TYPE commitType COMMIT_ID STR {yy.merge($2, $8, $6, $4)}
|
| MERGE ref COMMIT_TAG STR COMMIT_TYPE commitType COMMIT_ID STR {yy.merge($2, $8, $6, $4)}
|
||||||
| MERGE ID COMMIT_TAG STR COMMIT_ID STR COMMIT_TYPE commitType {yy.merge($2, $6, $8, $4)}
|
| MERGE ref COMMIT_TAG STR COMMIT_ID STR COMMIT_TYPE commitType {yy.merge($2, $6, $8, $4)}
|
||||||
;
|
;
|
||||||
|
|
||||||
commitStatement
|
commitStatement
|
||||||
@ -261,6 +261,11 @@ closeDirective
|
|||||||
: close_directive { yy.parseDirective('}%%', 'close_directive', 'gitGraph'); }
|
: close_directive { yy.parseDirective('}%%', 'close_directive', 'gitGraph'); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
ref
|
||||||
|
: ID
|
||||||
|
| STR
|
||||||
|
;
|
||||||
|
|
||||||
eol
|
eol
|
||||||
: NL
|
: NL
|
||||||
| ';'
|
| ';'
|
||||||
|
@ -114,7 +114,7 @@ In this example, we have given custom tags to the commits. Also, see how we have
|
|||||||
|
|
||||||
### Create a new branch
|
### Create a new branch
|
||||||
|
|
||||||
In Mermaid, in-order to create a new branch, you make use of the `branch` keyword. You also need to provide a name of the new branch. The name has to be unique and cannot be that of an existing branch. Usage example: `branch develop`
|
In Mermaid, in-order to create a new branch, you make use of the `branch` keyword. You also need to provide a name of the new branch. The name has to be unique and cannot be that of an existing branch. A branch name that could be confused for a keyword must be quoted within `""`. Usage examples: `branch develop`, `branch "cherry-pick"`
|
||||||
|
|
||||||
When Mermaid, reads the `branch` keyword, it creates a new branch and sets it as the current branch. Equivalent to you creating a new branch and checking it out in Git world.
|
When Mermaid, reads the `branch` keyword, it creates a new branch and sets it as the current branch. Equivalent to you creating a new branch and checking it out in Git world.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user