Skip to content

Commit parser field regexes should have conjunctive relationship #1612

Description

@sisp

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

I was trying to configure commit parsers that map conventional commits to a "Keep a Changelog" style changelog. One parser is intended to match feat: commits containing keywords like "remove" in conjunction with a BREAKING CHANGE footer and map matching commits to the Removed section. But it turns out that any commits containing a BREAKING CHANGE footer are now mapped to the Removed section. It seems that the fields in the same commit parser are matched disjunctively, i.e. if any one of those field regexes matches, the parser matches. I was expecting that all field regexes need to match for the parser to match, i.e. I was expecting a conjunctive relationship between the field regexes.

Steps To Reproduce

  1. Create an (empty) commit with the following commit message:

    fix: fix something
    
    BREAKING CHANGE: This fix is breaking.
    
  2. Create cliff.toml with the following content:

    [git]
    commit_parsers = [
      { message = "^feat!:.*?(remove|delete|drop)", group = "<!-- 3 -->Removed" },
      { message = "^feat:.*?(remove|delete|drop)", footer = "^BREAKING CHANGE:", group = "<!-- 3 -->Removed" },
      { message = "^fix", group = "<!-- 0 -->Fixed" }
    ]
  3. Run the following command:

    git-cliff -u --context
  4. Inspect the printed git-cliff context and observe that the commit message is mapped to the Removed group.

    git-cliff context
    [
      {
        "version": null,
        "message": null,
        "commits": [
          {
            "id": "35f070aab8e1a5c44f6ff3741e6def4d432f6c0c",
            "message": "fix something",
            "body": null,
            "footers": [
              {
                "token": "BREAKING CHANGE",
                "separator": ":",
                "value": "This fix is breaking.",
                "breaking": true
              }
            ],
            "group": "<!-- 3 -->Removed",
            "breaking_description": "This fix is breaking.",
            "breaking": true,
            "scope": null,
            "links": [],
            "author": {
              "name": "<REDACTED>",
              "email": "<REDACTED>",
              "timestamp": 1787345381
            },
            "committer": {
              "name": "<REDACTED>",
              "email": "<REDACTED>",
              "timestamp": 1787345459
            },
            "conventional": true,
            "merge_commit": false,
            "statistics": {
              "files_changed": 0,
              "additions": 0,
              "deletions": 0
            },
            "extra": null,
            "github": {
              "username": null,
              "pr_title": null,
              "pr_number": null,
              "pr_labels": [],
              "is_first_time": false
            },
            "gitlab": {
              "username": null,
              "pr_title": null,
              "pr_number": null,
              "pr_labels": [],
              "is_first_time": false
            },
            "gitea": {
              "username": null,
              "pr_title": null,
              "pr_number": null,
              "pr_labels": [],
              "is_first_time": false
            },
            "bitbucket": {
              "username": null,
              "pr_title": null,
              "pr_number": null,
              "pr_labels": [],
              "is_first_time": false
            },
            "azure_devops": {
              "username": null,
              "pr_title": null,
              "pr_number": null,
              "pr_labels": [],
              "is_first_time": false
            },
            "raw_message": "fix: fix something\n\nBREAKING CHANGE: This fix is breaking."
          }
        ],
        "commit_id": "35f070aab8e1a5c44f6ff3741e6def4d432f6c0c",
        "timestamp": null,
        "previous": null,
        "repository": "<REDACTED>",
        "commit_range": {
          "from": "35f070aab8e1a5c44f6ff3741e6def4d432f6c0c",
          "to": "35f070aab8e1a5c44f6ff3741e6def4d432f6c0c"
        },
        "submodule_commits": {},
        "statistics": {
          "commit_count": 1,
          "conventional_commit_count": 1,
          "links": []
        },
        "extra": null,
        "bump_type": null,
        "github": {
          "contributors": []
        },
        "gitlab": {
          "contributors": []
        },
        "gitea": {
          "contributors": []
        },
        "bitbucket": {
          "contributors": []
        },
        "azure_devops": {
          "contributors": []
        }
      }
    ]

Expected behavior

The commit should have been mapped to the Fixed group because I believe it's more intuitive to treat the field regexes of a commit parser as conjunctive.

Screenshots / Logs

No response

Software information

  • Operating system: Ubuntu 22.04
  • Rust version: n/a
  • Project version: 2.13.1

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions