Skip to content

Support --allow-merge-commits flag to skip validation of merge commits #133

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

Closed
bagowix opened this issue Apr 29, 2025 · 6 comments · Fixed by #134
Closed

Support --allow-merge-commits flag to skip validation of merge commits #133

bagowix opened this issue Apr 29, 2025 · 6 comments · Fixed by #134
Labels
bug Something isn't working

Comments

@bagowix
Copy link
Contributor

bagowix commented Apr 29, 2025

Hi!
Currently, conventional-pre-commit fails on merge commits because their commit messages (like Merge branch 'master' into feature/my-branch) do not follow the Conventional Commits standard.

It would be very useful to have an option like --allow-merge-commits to skip validation of merge commits automatically.

Use Case:

  • Developers merging master or other branches into feature branches.
  • CI pipelines where automatic merges happen.
  • Keeping history clean without manually editing merge commit messages.

Proposal:

  • Add a flag --allow-merge-commits.
  • If this flag is set, conventional-pre-commit should skip validation for commits that start with Merge ....
  • Ideally, detection could be done by checking if the commit message starts with Merge or using Git’s metadata.

Why it’s important:

  • Merge commits are common in many workflows.
  • Developers are forced to rewrite merge commit messages manually, which can break Git history clarity or cause frustration.
@thekaveman
Copy link
Member

Thanks for the detailed write-up @bagowix.

What version of conventional-pre-commit are you using? Since the latest version (v4.0.0, December 2024) the default behavior is to skip checking merge commits, meaning there is no need for a flag.

The --strict flag can be used to disallow merge commits and e.g. fixup! style commits. But otherwise, these are allowed by default.

@thekaveman thekaveman added duplicate This issue or pull request already exists question Further information is requested labels Apr 29, 2025
@bagowix
Copy link
Contributor Author

bagowix commented Apr 29, 2025

Hi, thanks again for the quick response!

I’m actually using conventional-pre-commit version v4.0.0, but I’m still consistently encountering this issue.
When I perform a regular merge (like merging master into my feature branch), the pre-commit hook blocks the commit with an error about a bad commit message, even though it’s a standard merge message.

  - repo: https://github.com/compilerla/conventional-pre-commit
    rev: v4.0.0
    hooks:
      - id: conventional-pre-commit
        stages: [commit-msg]
        args: [--verbose]

Here’s an example of the error I get:

Conventional Commit......................................................Failed
- hook id: conventional-pre-commit
- exit code: 1
[Bad commit message] >> Merge remote-tracking branch 'refs/remotes/origin/master' into feat/*****
Your commit message does not follow Conventional Commits formatting
https://www.conventionalcommits.org/
Conventional Commit messages follow a pattern like:
    type(scope): subject
    extended body
Please correct the following errors:
  - Expected value for type from: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test
Run:
    git commit --edit --file=.git/COMMIT_EDITMSG
to edit the commit message and retry the commit.
Not committing merge; use 'git commit' to complete the merge.

It seems like merge commits are still being validated.
Maybe there’s a configuration or usage detail I’m missing?

Would appreciate any advice or suggestions! Thanks again!

@thekaveman
Copy link
Member

Ah, thank you for sharing the error output, that was helpful! I think I see the issue:

[Bad commit message] >> Merge remote-tracking branch 'refs/remotes/origin/master' into feat/*****

We check for commit messages that start with "Merge branch", which of course doesn't work for your use-case of merging a remote branch. Sorry for this oversight!

I would happily accept a PR (with tests) to fix this.

@thekaveman thekaveman added bug Something isn't working and removed duplicate This issue or pull request already exists question Further information is requested labels Apr 29, 2025
@bagowix
Copy link
Contributor Author

bagowix commented Apr 29, 2025

I’d be happy to jump in and fix this!

@thekaveman
Copy link
Member

@bagowix
Copy link
Contributor Author

bagowix commented Apr 29, 2025

Thanks a lot for the quick review and merge! Appreciate the responsiveness - happy to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants