mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 14:29:25 +02:00
Merge pull request #6707 from mermaid-js/4838-gitgraph-chronology-duplicate-id
4838: Log warning for duplicate commit IDs in gitGraph
This commit is contained in:
5
.changeset/full-donuts-give.md
Normal file
5
.changeset/full-donuts-give.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'mermaid': patch
|
||||
---
|
||||
|
||||
fix: Log a warning when duplicate commit IDs are encountered in gitGraph to help identify and debug rendering issues caused by non-unique IDs.
|
@@ -1,4 +1,4 @@
|
||||
import { rejects } from 'assert';
|
||||
import { log } from '../../logger.js';
|
||||
import { db } from './gitGraphAst.js';
|
||||
import { parser } from './gitGraphParser.js';
|
||||
|
||||
@@ -1319,4 +1319,42 @@ describe('when parsing a gitGraph', function () {
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should log a warning when two commits have the same ID', async () => {
|
||||
const str = `gitGraph
|
||||
commit id:"initial commit"
|
||||
commit id:"work on first release"
|
||||
commit id:"design freeze from here"
|
||||
branch v1-rc
|
||||
checkout v1-rc
|
||||
commit id:"bugfix 1"
|
||||
commit id:"bigfix 2" tag:"v1.0.1"
|
||||
branch FORK-v1.0-MDR
|
||||
checkout FORK-v1.0-MDR
|
||||
commit id:"working on MDR"
|
||||
checkout v1-rc
|
||||
commit id:"minor design changes for MDR" tag:"v1.0.2"
|
||||
checkout FORK-v1.0-MDR
|
||||
merge v1-rc
|
||||
checkout main
|
||||
commit id:"new feature for v1.1…"
|
||||
checkout FORK-v1.0-MDR
|
||||
commit id:"working on MDR"
|
||||
commit id:"finishing MDR"
|
||||
branch v1.0-MDR
|
||||
checkout v1.0-MDR
|
||||
commit id:"brush up release" tag:"v1.0.2-MDR"
|
||||
checkout v1-rc
|
||||
commit id:"bugfix without MDR"
|
||||
checkout main
|
||||
commit id:"work on v1.1"
|
||||
`;
|
||||
|
||||
const logWarnSpy = vi.spyOn(log, 'warn').mockImplementation(() => undefined);
|
||||
|
||||
await parser.parse(str);
|
||||
|
||||
expect(logWarnSpy).toHaveBeenCalledWith('Commit ID working on MDR already exists');
|
||||
|
||||
logWarnSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
@@ -125,6 +125,9 @@ export const commit = function (commitDB: CommitDB) {
|
||||
};
|
||||
state.records.head = newCommit;
|
||||
log.info('main branch', config.mainBranchName);
|
||||
if (state.records.commits.has(newCommit.id)) {
|
||||
log.warn(`Commit ID ${newCommit.id} already exists`);
|
||||
}
|
||||
state.records.commits.set(newCommit.id, newCommit);
|
||||
state.records.branches.set(state.records.currBranch, newCommit.id);
|
||||
log.debug('in pushCommit ' + newCommit.id);
|
||||
|
Reference in New Issue
Block a user