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

Unable to cherry-pick a merge commit #4497

Closed
vermiculus opened this issue Jun 16, 2023 · 2 comments · Fixed by #4944
Closed

Unable to cherry-pick a merge commit #4497

vermiculus opened this issue Jun 16, 2023 · 2 comments · Fixed by #4944

Comments

@vermiculus
Copy link

Description

When I cherry-pick a merge commit, I receive the error:

Incorrect usage of "cherryPick". Source commit should not be a merge commit

This is coming from gitGraphAst:cherryPick.

As discussed in #3238, cherry-picking merge commits is a relatively common procedure. While merge commits can now be given an ID (presumably implemented in #3238), that ID cannot be leveraged for cherry-picking - at least in the MWE given below.

Seems to be caused by c147404 (#3080).

Steps to reproduce

See live editor.

Screenshots

No response

Code Sample

gitGraph
  commit
  branch feature
  branch release
  checkout feature
  commit id: "A"
  commit id: "B"
  checkout main
  merge feature id: "M"
  checkout release
  cherry-pick id: "M"

Setup

  • Mermaid version: v10.2.3
  • Browser and Version: [Chrome, Edge, Firefox] Chrome 114.0.5735.133

Additional Context

No response

@vermiculus vermiculus added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Jun 16, 2023
@vermiculus
Copy link
Author

Is this as simple as removing the following block? I don't see any downstream assumptions, but this codebase is new to me.

  if (sourceCommit.type === commitType.MERGE) {
    let error = new Error(
      'Incorrect usage of "cherryPick". Source commit should not be a merge commit'
    );
    error.hash = {
      text: 'cherryPick ' + sourceId + ' ' + targetId,
      token: 'cherryPick ' + sourceId + ' ' + targetId,
      line: '1',
      loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
      expected: ['cherry-pick abc'],
    };
    throw error;
  }

@RounakJoshi09
Copy link
Contributor

Hello @sidharthv96 , This seems to be a valid concern/issue regarding cherry-picking merge commits. The issue arises because merge commits have multiple parent commits, leaving Git unsure about which parent to compare against for generating the diff. An additional flag is needed to clarify this. I've reviewed the codebase and believe I can contribute a solution to address this. Could you please assign this issue to me? I'll prioritize working on it.

Feel free to use or adapt this as you see fit.

Source - https://git-scm.com/docs/git-cherry-pick

github-merge-queue bot pushed a commit that referenced this issue Dec 4, 2023
…ypick-merge-commit

Bug/#4497 Unable to Cherry Pick Merge Commit Solved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants