mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-11-04 04:44:08 +01:00 
			
		
		
		
	gitgraph #2934 support tags for merge commits
This commit is contained in:
		@@ -136,7 +136,7 @@ export const branch = function (name) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const merge = function (otherBranch) {
 | 
					export const merge = function (otherBranch, tag) {
 | 
				
			||||||
  otherBranch = common.sanitizeText(otherBranch, configApi.getConfig());
 | 
					  otherBranch = common.sanitizeText(otherBranch, configApi.getConfig());
 | 
				
			||||||
  const currentCommit = commits[branches[curBranch]];
 | 
					  const currentCommit = commits[branches[curBranch]];
 | 
				
			||||||
  const otherCommit = commits[branches[otherBranch]];
 | 
					  const otherCommit = commits[branches[otherBranch]];
 | 
				
			||||||
@@ -213,6 +213,7 @@ export const merge = function (otherBranch) {
 | 
				
			|||||||
    parents: [head == null ? null : head.id, branches[otherBranch]],
 | 
					    parents: [head == null ? null : head.id, branches[otherBranch]],
 | 
				
			||||||
    branch: curBranch,
 | 
					    branch: curBranch,
 | 
				
			||||||
    type: commitType.MERGE,
 | 
					    type: commitType.MERGE,
 | 
				
			||||||
 | 
					    tag: tag ? tag : '',
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  head = commit;
 | 
					  head = commit;
 | 
				
			||||||
  commits[commit.id] = commit;
 | 
					  commits[commit.id] = commit;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -411,6 +411,41 @@ describe('when parsing a gitGraph', function () {
 | 
				
			|||||||
    ]);
 | 
					    ]);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it('should handle merge tags', function () {
 | 
				
			||||||
 | 
					    const str = `gitGraph:
 | 
				
			||||||
 | 
					    commit
 | 
				
			||||||
 | 
					    branch testBranch
 | 
				
			||||||
 | 
					    checkout testBranch
 | 
				
			||||||
 | 
					    commit
 | 
				
			||||||
 | 
					    checkout main
 | 
				
			||||||
 | 
					    merge testBranch tag: "merge-tag"
 | 
				
			||||||
 | 
					    `;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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[commit1].parents).toStrictEqual([]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    expect(commits[commit2].branch).toBe('testBranch');
 | 
				
			||||||
 | 
					    expect(commits[commit2].parents).toStrictEqual([commits[commit1].id]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    expect(commits[commit3].branch).toBe('main');
 | 
				
			||||||
 | 
					    expect(commits[commit3].parents).toStrictEqual([commits[commit1].id, commits[commit2].id]);
 | 
				
			||||||
 | 
					    expect(commits[commit3].tag).toBe('merge-tag');
 | 
				
			||||||
 | 
					    expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([
 | 
				
			||||||
 | 
					      { name: 'main' },
 | 
				
			||||||
 | 
					      { name: 'testBranch' },
 | 
				
			||||||
 | 
					    ]);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('should throw error when try to branch existing branch: main', function () {
 | 
					  it('should throw error when try to branch existing branch: main', function () {
 | 
				
			||||||
    const str = `gitGraph
 | 
					    const str = `gitGraph
 | 
				
			||||||
    commit
 | 
					    commit
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,11 +89,17 @@ line
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
statement
 | 
					statement
 | 
				
			||||||
    : commitStatement
 | 
					    : commitStatement
 | 
				
			||||||
 | 
					    | mergeStatement
 | 
				
			||||||
    | BRANCH ID {yy.branch($2)}
 | 
					    | BRANCH ID {yy.branch($2)}
 | 
				
			||||||
    | CHECKOUT ID {yy.checkout($2)}
 | 
					    | CHECKOUT ID {yy.checkout($2)}
 | 
				
			||||||
    | MERGE ID {yy.merge($2)}
 | 
					 | 
				
			||||||
    // | RESET reset_arg {yy.reset($2)}
 | 
					    // | RESET reset_arg {yy.reset($2)}
 | 
				
			||||||
    ;
 | 
					    ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mergeStatement
 | 
				
			||||||
 | 
					    : MERGE ID {yy.merge($2)}
 | 
				
			||||||
 | 
					    | MERGE ID COMMIT_TAG STR {yy.merge($2, $4)}
 | 
				
			||||||
 | 
					    ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
commitStatement
 | 
					commitStatement
 | 
				
			||||||
    : COMMIT commit_arg {yy.commit($2)}
 | 
					    : COMMIT commit_arg {yy.commit($2)}
 | 
				
			||||||
    | COMMIT COMMIT_TAG STR {yy.commit('','',yy.commitType.NORMAL,$3)}
 | 
					    | COMMIT COMMIT_TAG STR {yy.commit('','',yy.commitType.NORMAL,$3)}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user