mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-17 14:29:48 +02:00
feat(git): allow custom merge commit ids
Currently, merge commits can have a git tag, but they cannot have a
custom git commit ID.
This commit allows modifying the default merge commit id.
It also displays all merge commits IDs, which undoes
3ccf027f42
This commit is contained in:
@@ -496,6 +496,76 @@ describe('when parsing a gitGraph', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle merge ids', function () {
|
||||
const str = `gitGraph:
|
||||
commit
|
||||
branch testBranch
|
||||
checkout testBranch
|
||||
commit
|
||||
checkout main
|
||||
%% Merge Tag and ID
|
||||
merge testBranch tag: "merge-tag" id: "2-222"
|
||||
branch testBranch2
|
||||
checkout testBranch2
|
||||
commit
|
||||
checkout main
|
||||
%% Merge ID and Tag (reverse order)
|
||||
merge testBranch2 id: "4-444" tag: "merge-tag2"
|
||||
branch testBranch3
|
||||
checkout testBranch3
|
||||
commit
|
||||
checkout main
|
||||
%% just Merge ID
|
||||
merge testBranch3 id: "6-666"
|
||||
`;
|
||||
|
||||
parser.parse(str);
|
||||
const commits = parser.yy.getCommits();
|
||||
expect(Object.keys(commits).length).toBe(7);
|
||||
expect(parser.yy.getCurrentBranch()).toBe('main');
|
||||
expect(parser.yy.getDirection()).toBe('LR');
|
||||
|
||||
// The order of these commits is in alphabetical order of IDs
|
||||
const [
|
||||
mainCommit,
|
||||
testBranchCommit,
|
||||
testBranchMerge,
|
||||
testBranch2Commit,
|
||||
testBranch2Merge,
|
||||
testBranch3Commit,
|
||||
testBranch3Merge,
|
||||
] = Object.values(commits);
|
||||
|
||||
console.log(Object.keys(commits));
|
||||
|
||||
expect(mainCommit.branch).toBe('main');
|
||||
expect(mainCommit.parents).toStrictEqual([]);
|
||||
|
||||
expect(testBranchCommit.branch).toBe('testBranch');
|
||||
expect(testBranchCommit.parents).toStrictEqual([mainCommit.id]);
|
||||
|
||||
expect(testBranchMerge.branch).toBe('main');
|
||||
expect(testBranchMerge.parents).toStrictEqual([mainCommit.id, testBranchCommit.id]);
|
||||
expect(testBranchMerge.tag).toBe('merge-tag');
|
||||
expect(testBranchMerge.id).toBe('2-222');
|
||||
|
||||
expect(testBranch2Merge.branch).toBe('main');
|
||||
expect(testBranch2Merge.parents).toStrictEqual([testBranchMerge.id, testBranch2Commit.id]);
|
||||
expect(testBranch2Merge.tag).toBe('merge-tag2');
|
||||
expect(testBranch2Merge.id).toBe('4-444');
|
||||
|
||||
expect(testBranch3Merge.branch).toBe('main');
|
||||
expect(testBranch3Merge.parents).toStrictEqual([testBranch2Merge.id, testBranch3Commit.id]);
|
||||
expect(testBranch3Merge.id).toBe('6-666');
|
||||
|
||||
expect(parser.yy.getBranchesAsObjArray()).toStrictEqual([
|
||||
{ name: 'main' },
|
||||
{ name: 'testBranch' },
|
||||
{ name: 'testBranch2' },
|
||||
{ name: 'testBranch3' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should throw error when try to branch existing branch: main', function () {
|
||||
const str = `gitGraph
|
||||
commit
|
||||
|
Reference in New Issue
Block a user