Skip to content

Output only merge commits into the default branch #143

@hituzi-no-sippo

Description

@hituzi-no-sippo

Overview

I want to output only merge commits into the default branch (main).
I've thought of my own solution, but is there a better one out there?

Description

Example Repository
hituzi-no-sippo/merge-commit-only-git-cliff

For the following git log

git log

git log --graph --pretty="%H%n%n%B" HEAD^

*   f24c87f2ec023cb37b25957f0c678ba50d3f7cf2
|\
| | fix: donut merge commit
| |
| | Merge branch 'donut'
| |
| * cf727a7ca7ab6ad7f6f39739cb24f5ddb7a7508f
|/
|   fix: donut
|
*   2c211a56a0d80f84b7fe89b008f780bc56b20938
|\
| | feat: banana merge commit
| |
| | Merge branch 'banana'
| |
| *   0838fcb8336885399a6f9a3cd51de4751660d4f1
| |\
| | | perf: cacao merge commit
| | |
| | | Merge branch 'banan-cacao' into banana
| | |
| | * c32be0364e58a5cb6c9f41a7f642fc480d60ae26
| |/
| |   perf: cacao
| |
| * 1c744d48aeb64ab0b6d20abc6d09c4d2c531f498
|/
|   feat: banana
|
*   93ad4a4b7f8c25ecadede3b35c58fe85178ffe4d
|\
| | chore: apple merge commit
| |
| | Merge branch 'apple'
| |
| * 609b30e1e2adb2353205725f92a8bbd2a99a4b3a
|/
|   chore: apple
|
* c7bfa61551d821feb0cc8f71542b64a8750c9cec

  Initial commit

I want to output only the next commit in CHANGELOG.

git log

git log --graph --pretty="%H%n%n%B"

* f24c87f2ec023cb37b25957f0c678ba50d3f7cf2
|
| fix: donut merge commit
|
| Merge branch 'donut'
|
* 2c211a56a0d80f84b7fe89b008f780bc56b20938
|
| feat: banana merge commit
|
| Merge branch 'banana'
|
* 93ad4a4b7f8c25ecadede3b35c58fe85178ffe4d

  chore: apple merge commit

  Merge branch 'apple'

CHANGELOG

Expected

Details
# Changelog

All notable changes to this project will be documented in this file.

## [unreleased]

### Bug Fixes

- Donut merge commit

### Features

- Banana merge commit

### Miscellaneous Tasks

- Apple merge commit

<!-- generated by git-cliff -->

default config(git-cliff --init)

Details
# Changelog

All notable changes to this project will be documented in this file.

## [unreleased]

### Bug Fixes

- Donut
- Donut merge commit

### Features

- Banana
- Banana merge commit

### Miscellaneous Tasks

- Apple
- Apple merge commit

### Performance

- Cacao
- Cacao merge commit

<!-- generated by git-cliff -->

diff

hituzi-no-sippo/merge-commit-only-git-cliff/CHANGELOG.diff

--- default.md	2023-02-05 19:59:53.498790000 +0900
+++ merge-commit-only.md	2023-02-05 19:59:58.658790000 +0900
@@ -6,22 +6,14 @@
 
 ### Bug Fixes
 
-- Donut
 - Donut merge commit
 
 ### Features
 
-- Banana
 - Banana merge commit
 
 ### Miscellaneous Tasks
 
-- Apple
 - Apple merge commit
 
-### Performance
-
-- Cacao
-- Cacao merge commit
-
 <!-- generated by git-cliff -->

Why skip normal commit

A merge commit contains a portion of content that is not a merge commit.

I solution considered

  • Add .*\n+Merge branch '.*'\n$ to message in commit_parsers
  • Change filter_commits to true

Diff

hituzi-no-sippo/merge-commit-only-git-cliff/config.diff

--- cliff.toml	2023-02-05 19:57:23.288790000 +0900
+++ merge-commit-only.toml	2023-02-05 19:57:41.898790000 +0900
@@ -42,21 +42,21 @@
 ]
 # regex for parsing and grouping commits
 commit_parsers = [
-    { message = "^feat", group = "Features"},
-    { message = "^fix", group = "Bug Fixes"},
-    { message = "^doc", group = "Documentation"},
-    { message = "^perf", group = "Performance"},
-    { message = "^refactor", group = "Refactor"},
-    { message = "^style", group = "Styling"},
-    { message = "^test", group = "Testing"},
-    { message = "^chore\\(release\\): prepare for", skip = true},
-    { message = "^chore", group = "Miscellaneous Tasks"},
-    { body = ".*security", group = "Security"},
+    { message = "^feat.*\n+Merge branch '.*'\n$", group = "Features"},
+    { message = "^fix.*\n+Merge branch '.*'\n$", group = "Bug Fixes"},
+    { message = "^doc.*\n+Merge branch '.*'\n$", group = "Documentation"},
+    { message = "^perf.*\n+Merge branch '.*'\n$", group = "Performance"},
+    { message = "^refactor.*\n+Merge branch '.*'\n$", group = "Refactor"},
+    { message = "^style.*\n+Merge branch '.*'\n$", group = "Styling"},
+    { message = "^test.*\n+Merge branch '.*'\n$", group = "Testing"},
+    { message = "^chore\\(release\\): prepare for.*\n+Merge branch '.*'\n$", skip = true},
+    { message = "^chore.*\n+Merge branch '.*'\n$", group = "Miscellaneous Tasks"},
+    { body = ".*security.*\n+Merge branch '.*'\n$", group = "Security"},
 ]
 # protect breaking changes from being skipped due to matching a skipping commit_parser
 protect_breaking_commits = false
 # filter out the commits that are not matched by commit parsers
-filter_commits = false
+filter_commits = true
 # glob pattern for matching git tags
 tag_pattern = "v[0-9]*"
 # regex for skipping tags

Additional context

I am wondering if I should feature request to output only merge commits to the default branch.
Because I don't know if many people use this output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    how-toTip about achieving something

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions