Merge pull request #2955 from husa/feature/2934-gitgraph-support-merge-tags

GitGraph. Support tags for merge commits
This commit is contained in:
Ashish Jain 2022-04-21 20:09:31 +02:00 committed by GitHub
commit 1947af0693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 3 deletions

View File

@ -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());
const currentCommit = commits[branches[curBranch]];
const otherCommit = commits[branches[otherBranch]];
@ -213,6 +213,7 @@ export const merge = function (otherBranch) {
parents: [head == null ? null : head.id, branches[otherBranch]],
branch: curBranch,
type: commitType.MERGE,
tag: tag ? tag : '',
};
head = commit;
commits[commit.id] = commit;

View File

@ -255,7 +255,7 @@ describe('when parsing a gitGraph', function () {
it('should handle a gitGraph commit with custom type,tag, msg, commit id,', function () {
const str = `gitGraph:
commit type:REVERSE tag: "test tag" msg: "test msg" id: "1111"
`;
parser.parse(str);
@ -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 () {
const str = `gitGraph
commit

View File

@ -89,11 +89,17 @@ line
statement
: commitStatement
| mergeStatement
| BRANCH ID {yy.branch($2)}
| CHECKOUT ID {yy.checkout($2)}
| MERGE ID {yy.merge($2)}
// | RESET reset_arg {yy.reset($2)}
;
mergeStatement
: MERGE ID {yy.merge($2)}
| MERGE ID COMMIT_TAG STR {yy.merge($2, $4)}
;
commitStatement
: COMMIT commit_arg {yy.commit($2)}
| COMMIT COMMIT_TAG STR {yy.commit('','',yy.commitType.NORMAL,$3)}