log warning when duplicate commit IDs are encountered

This commit is contained in:
darshanr0107
2025-07-02 11:59:20 +05:30
parent d9396eedd6
commit da0c6c6c32
2 changed files with 36 additions and 0 deletions

View File

@@ -1569,4 +1569,37 @@ gitGraph TB:
{} {}
); );
}); });
it('77:should render gitGraph with duplicate commit IDs and log warnings', () => {
imgSnapshotTest(
`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"`,
{}
);
cy.log('Warning: Commit ID "working on MDR" already exists');
});
}); });

View File

@@ -125,6 +125,9 @@ export const commit = function (commitDB: CommitDB) {
}; };
state.records.head = newCommit; state.records.head = newCommit;
log.info('main branch', config.mainBranchName); 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.commits.set(newCommit.id, newCommit);
state.records.branches.set(state.records.currBranch, newCommit.id); state.records.branches.set(state.records.currBranch, newCommit.id);
log.debug('in pushCommit ' + newCommit.id); log.debug('in pushCommit ' + newCommit.id);