Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/#4497 Unable to Cherry Pick Merge Commit Solved #4944

Conversation

RounakJoshi09
Copy link
Contributor

@RounakJoshi09 RounakJoshi09 commented Oct 13, 2023

📑 Summary

Cherry-pick a merge commit, requires a special flag because merge commits have more than one parent. When you cherry-pick a regular commit, Git knows to take the changes from the parent commit to the chosen commit. In the case of a merge commit, there are multiple parent commits, so you have to specify which parent's context you want to use for the cherry-pick.
If you try to cherry-pick a merge commit without specifying a parent, Git won't know what changes to apply and will prompt you to specify a mainline parent.

Resolves #4497

📏 Design Decisions

The Pull Request addresses this issue by introducing additional syntax to the parser and modifying the cherryPick function to handle merge commit cherry-picking scenarios properly. Specifically:

A new identifier, PARENT_COMMIT, was introduced in the parser syntax to allow users to specify the parent commit when cherry-picking a merge commit.

The cherryPick function was enhanced to validate and handle the parentCommitId parameter when dealing with merge commits. It now checks if the specified parent commit is an immediate parent of the merge commit being cherry-picked and throws descriptive errors when incorrect usage is detected.
The function also handles tagging and branch checks to ensure the cherry-pick operation's correctness and to provide informative feedback to the user regarding any incorrect usage.

With these enhancements, users can now accurately represent cherry-picking merge commits within their Mermaid Git diagrams, improving the library's functionality and usability for illustrating complex Git workflows. The new syntax and function logic cover various cherry-picking scenarios, providing a robust solution to the initially reported problem.

📋 Tasks

Make sure you

@netlify
Copy link

netlify bot commented Oct 13, 2023

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit d22ee8d
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/656d673643ec2900084320f9
😎 Deploy Preview https://deploy-preview-4944--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codecov
Copy link

codecov bot commented Oct 14, 2023

Codecov Report

Merging #4944 (d22ee8d) into develop (f81e4d4) will decrease coverage by 0.04%.
The diff coverage is 66.66%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4944      +/-   ##
===========================================
- Coverage    79.41%   79.38%   -0.04%     
===========================================
  Files          166      166              
  Lines        13871    13874       +3     
  Branches       705      705              
===========================================
- Hits         11016    11014       -2     
- Misses        2703     2708       +5     
  Partials       152      152              
Flag Coverage Δ
e2e 85.19% <66.66%> (-0.05%) ⬇️
unit 43.03% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/mermaid/src/diagrams/git/gitGraphAst.js 56.50% <66.66%> (+0.15%) ⬆️

... and 3 files with indirect coverage changes

Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @RounakJoshi09, nice work. You'll need to add some E2E tests also, by adding a test in cypress/integration/rendering/gitGraph.spec.js.
This will ensure correct rendering.

packages/mermaid/src/docs/syntax/gitgraph.md Show resolved Hide resolved
packages/mermaid/src/diagrams/git/parser/gitGraph.jison Outdated Show resolved Hide resolved
packages/mermaid/src/diagrams/git/gitGraphAst.js Outdated Show resolved Hide resolved
packages/mermaid/src/diagrams/git/gitGraphAst.js Outdated Show resolved Hide resolved
@RounakJoshi09
Copy link
Contributor Author

Hi @sidharthv96 I have made all the suggested changes and also added E2E test for cherry picking merge Commit. Could you please check it once. Thanks

@jgreywolf
Copy link
Contributor

@RounakJoshi09 Have you had a chance to review @sidharthv96 most recent change request?

@RounakJoshi09
Copy link
Contributor Author

Hi @jgreywolf I am working on requested changes , It will be done by tommorow anyhow

@github-actions github-actions bot added the Type: Bug / Error Something isn't working or is incorrect label Nov 17, 2023
@sidharthv96 sidharthv96 requested a review from nirname November 27, 2023 06:45
@sidharthv96 sidharthv96 added this to the v10 milestone Nov 28, 2023
Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

I do have a potential improvement so that a bad parent: "xxxx" throws an error, even if we're not cherry-pick-ing a merge commit, but it's pretty minor, and this PR has been open for a while, so we can always make that change in another PR!

packages/mermaid/src/diagrams/git/gitGraphAst.js Outdated Show resolved Hide resolved
@sidharthv96
Copy link
Member

@RounakJoshi09 was 31a1de1 reverted due to the failing CI? If so, it's unrelated and you can force push 31a1de1 again.

@sidharthv96 sidharthv96 force-pushed the bug/#4497_unable-to-cherrypick-merge-commit branch from fefe687 to 31a1de1 Compare December 4, 2023 04:54
@RounakJoshi09
Copy link
Contributor Author

Hello @sidharthv96 , I explicitly reverted the commit because after adding the changes by @aloisklink , Unit test and E2E are failing, which I will look today. Or if the issue mentioned by @aloisklink, is not major , and can be fixed in another PR, we can merge this PR, with the previous commit.

@sidharthv96
Copy link
Member

Ahh, that error was because it was not checking if parentCommitId was present or not. The unit test errors have now been fixed. Waiting for E2E in CI.

@RounakJoshi09
Copy link
Contributor Author

Thankyou @sidharthv96 for fixing this, E2E have also been passed, and condition requested by @aloisklink is also added. 😊

Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! It all looks great! Thanks for making those changes (and thanks @sidharthv96 for the help!)

@aloisklink aloisklink added this pull request to the merge queue Dec 4, 2023
Merged via the queue into mermaid-js:develop with commit 6a31ae6 Dec 4, 2023
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Graph: Git Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to cherry-pick a merge commit
5 participants