#3238 Merge from 'develop'

This commit is contained in:
ashishj 2022-08-30 18:11:10 +02:00
commit d2aaf6aad9
4 changed files with 76 additions and 2 deletions

View File

@ -74,7 +74,7 @@ describe('Git Graph diagram', () => {
{}
);
});
it('7: should render a simple gitgraph with three branches and merge commit', () => {
it('7: should render a simple gitgraph with three branches and tagged merge commit', () => {
imgSnapshotTest(
`gitGraph
commit id: "1"
@ -93,7 +93,7 @@ describe('Git Graph diagram', () => {
checkout nice_feature
commit id: "7"
checkout main
merge nice_feature
merge nice_feature id: "12345" tag: "my merge commit"
checkout very_nice_feature
commit id: "8"
checkout main

View File

@ -182,6 +182,8 @@ After this we made use of the `checkout` keyword to set the current branch as `m
After this we merge the `develop` branch onto the current branch `main`, resulting in a merge commit.
Since the current branch at this point is still `main`, the last two commits are registered against that.
Additionally, you may add a tag to the merge commit, or override the default id: `merge branch id:"1234" tag:"v1.0.0"`
### Cherry Pick commit from another branch
Similar to how 'git' allows you to cherry-pick a commit from **another branch** onto the **current** branch, Mermaid also supports this functionality. You can also cherry-pick a commit from another branch using the `cherry-pick` keyword.

View File

@ -150,6 +150,8 @@ export const branch = function (name, order) {
export const merge = function (otherBranch, custom_id, override_type, custom_tag) {
otherBranch = common.sanitizeText(otherBranch, configApi.getConfig());
custom_id = common.sanitizeText(custom_id, configApi.getConfig());
const currentCommit = commits[branches[curBranch]];
const otherCommit = commits[branches[otherBranch]];
if (curBranch === otherBranch) {

View File

@ -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