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

Wrong commit assignment to tags #498

Open
cweber-dbs opened this issue Feb 13, 2024 · 3 comments
Open

Wrong commit assignment to tags #498

cweber-dbs opened this issue Feb 13, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@cweber-dbs
Copy link

cweber-dbs commented Feb 13, 2024

Describe the bug

The assignment of the commits to a tag is based on the creation time of the commits and not based on the topological order of the commits in different branches.

  1. Create a new branch 'feature' from 'main'
  2. Create a commit 'fix: m1' in 'main'
  3. Create a commit 'fix: f1' in 'feature'
  4. Create a commit 'fix: m2' in 'main' and add a tag '1.0.0' to this commit
  5. Create a commit 'fix: f2' in 'feature'
  6. merge 'feature' in main and add a tag '1.1.0' to this merge commit

The created changelog adds commit 'f1' to tag '1.0.0'

Expected behavior

Commits 'fix: m1' and 'fix: m2' should be assigned to Tag '1.0.0.
Commits 'fix: f1' and 'fix: f2' should be assigned to Tag '1.1.0.

Screenshots / Logs
Git Graph of Commits:
image

Created Changelog with wrong assignment:
image

Software information

  • Operating system: macOS 14.3.1
  • Project version: 1.4.0

Additional context

cliff.toml:

# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration
#
# Lines starting with "#" are comments.
# Configuration options are organized into tables and keys.
# See documentation for more information on available options.

[changelog]
# changelog header
header = """
# Changelog\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version %}\
    {% if previous.version %}\
        ## [{{ version | trim_start_matches(pat="v") }}](${CI_PROJECT_URL}/compare/{{ previous.version }}\\...{{ version }}) ({{ timestamp | date(format="%Y-%m-%d") }})
    {% else %}\
        ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
    {% endif %}\
{% else %}\
    ## [unreleased]
{% endif %}\

{% macro commit(commit) -%}
    * {% if commit.scope %}**{{ commit.scope }}:** {% endif %}{% if commit.breaking %}[**breaking**] {% endif %}\
        {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=8, end="") }}](${CI_PROJECT_URL}/-/commit/{{ commit.id }}))\
{% endmacro -%}

{% for group, commits in commits | group_by(attribute="group") %}
    ### {{ group | striptags | trim | upper_first }}
    {% for commit in commits
    | filter(attribute="scope")
    | sort(attribute="scope") %}
        {{ self::commit(commit=commit) }}
    {%- endfor -%}
    {% raw %}\n{% endraw %}\
    {%- for commit in commits %}
        {%- if not commit.scope -%}
            {{ self::commit(commit=commit) }}
        {% endif -%}
    {% endfor -%}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
\n
"""
# remove the leading and trailing whitespace from the templates
trim = true
# postprocessors
postprocessors = []

[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = true
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = []
# regex for parsing and grouping commits
commit_parsers = [
  { message = "^feat", group = "<!-- 0 -->Features" },
  { message = "^fix", group = "<!-- 1 -->Bug Fixes" },
  { message = "^refactor", group = "<!-- 2 -->Refactor" },
  { message = "^perf", group = "<!-- 3 -->Performance" },
  { message = "^revert", group = "<!-- 4 -->Revert" },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = true
# filter out the commits that are not matched by commit parsers
filter_commits = true
# regex for matching git tags
tag_pattern = "^v{0,1}[0-9]*\\.[0-9]*\\.[0-9]*.*"
# regex for skipping tags
# skip_tags = "beta|alpha"
# regex for ignoring tags
# ignore_tags = "rc"
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "newest"
@cweber-dbs cweber-dbs added the bug Something isn't working label Feb 13, 2024
Copy link

welcome bot commented Feb 13, 2024

Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️

@alerque
Copy link
Contributor

alerque commented Aug 13, 2024

I just ran into this too. I've had a long running branch for re-licensing a project and am cutting a release with that being the only change that should make it into the changelog. Running git cliff -o CHANGELOG.md -t vX.Y.Z regenerated the changelog but, the breaking change was just added as an entry to a release 4 releases ago and no heading for X.Y.Z was even added! I might have missed if this was happening with just a few commits coming in from old branch points, but this one is pretty egregious.

If you want re replicate the results for testing you can clone decasify and then git checkout v0.6.0^ to get the commit before the release I had to hand-generate notes for, then git cliff -o CHANGELOG.md -t v0.6.0 to see where Git Cliff wants to put the notes.

Using git log v0.5.8..v0.6.0 shows the correct topological set of commits that entered the branch during that release cycle.

@orhun
Copy link
Owner

orhun commented Aug 23, 2024

@alerque maybe it is about #804?

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

No branches or pull requests

3 participants