orhun / git-cliff

A highly customizable Changelog Generator that follows Conventional Commit specifications ā›°ļø
https://git-cliff.org
Apache License 2.0
9.25k stars 198 forks source link

Previous not populated when using --latest and skip_tags are set but don't match #44

Closed iCrawl closed 2 years ago

iCrawl commented 2 years ago

Describe the bug If skip_tags is defined with a regex that correctly generates the changelog (by skipping the correct/defined ones), there is a regression when setting previous and using --latest which was supposed to be fixed here: https://github.com/orhun/git-cliff/issues/3

But it looks like if you use --latest in combination with skip_tags, even if the pattern should not match the tag at all, it will simply not populate the previous field. This might have been introduced here(?): https://github.com/orhun/git-cliff/commit/7f867ae647ff30f54aae314596cbc7c7ce4f50c1

If I remove the skip_tags from the config while generating with --latest, previous is populated as expected.

To Reproduce Steps to reproduce the behavior:

[changelog]
header = """
# Changelog
All notable changes to this project will be documented in this file.\n
"""
body = """
{% if version %}\
    # [{{ version | trim_start_matches(pat="v") }}]\
    {% if previous %}\
        {% if previous.version %}\
            (https://github.com/discordjs/discord.js/compare/{{ previous.version }}...{{ version }})\
        {% else %}
            (https://github.com/discordjs/discord.js/tree/{{ version }}\
        {% endif %}\
    {% endif %} \
    - ({{ timestamp | date(format="%Y-%m-%d") }})
{% else %}\
    # [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
    ## {{ group | upper_first }}
    {% for commit in commits %}
        - {% if commit.breaking %}\
            [**breaking**] \
          {% endif %}\
            {% if commit.scope %}\
                **{{commit.scope}}:** \
            {% endif %}\
            {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/discordjs/discord.js/commit/{{ commit.id }}))\
    {% endfor %}
{% endfor %}\n
"""
trim = true
footer = ""

[git]
conventional_commits = true
filter_unconventional = true
tag_pattern = "[0-9]*"
skip_tags = "v[0-9]*|11|12"
ignore_tags = ""

All tags on the repo in question:

10.0.0
10.0.1
11.0.0
11.1.0
11.2.0
11.3.0
11.3.1
11.3.2
11.4.0
11.4.1
11.4.2
11.5.0
11.5.1
11.6.0
11.6.1
11.6.2
11.6.3
11.6.4
12.0.0
12.0.1
12.0.2
12.1.0
12.1.1
12.2.0
12.3.0
12.3.1
12.4.0
12.4.1
12.5.0
12.5.1
12.5.2
12.5.3
13.0.0
13.0.1
13.1.0
13.2.0
13.3.0
13.3.1
13.4.0
13.5.0
5.2.0
5.3.2
6.0.0
6.1.0
7.0.0
7.0.1
8.0.0
8.1.0
8.2.0
9.0.2
9.1.0
9.1.1
9.2.0
9.3.0
9.3.1
v5.0.0
v5.0.1
v5.1.0
v5.3.0
v5.3.1

Expected behavior Expect skip_tags to not drop unrelated tags from the previous field.

System (please complete the following information):

orhun commented 2 years ago

Hello, good catch!

This should be fixed in 943c23f, can you try it out and let me know if it works as expected?

iCrawl commented 2 years ago

Yes, that did indeed solve it, I do have another question about this, it might be semi-related? Please do tell if you want a separate issue about this but:

Let's presume I want to run something like this: git cliff --prepend CHANGELOG.md -l which works with the changes/fixes you made now properly and populated previous and everything to correctly give me all the info I need. But with this approach I need to manually git tag a release, then run the command with the --latest flag to get the diff between the two tags and such the commits.

But ideally, I would want to run something like this: git cliff --prepend CHANGELOG.md --unreleased --tag 14.0.0

Is this somehow possible or not at all? Since previous does not seem to get populated if I do it this way, without manually creating the tag before.

orhun commented 2 years ago

Yes, that did indeed solve it,

Thanks for testing this out!

Please do tell if you want a separate issue about this

Yes, that would be nice šŸ‘šŸ¼

Let's presume I want to run something like this: git cliff --prepend CHANGELOG.md -l which works with the changes/fixes you made now properly and populated previous and everything to correctly give me all the info I need. But with this approach I need to manually git tag a release, then run the command with the --latest flag to get the diff between the two tags and such the commits.

But ideally, I would want to run something like this: git cliff --prepend CHANGELOG.md --unreleased --tag 14.0.0

Is this somehow possible or not at all? Since previous does not seem to get populated if I do it this way, without manually creating the tag before.

This is supposed to be possible. Actually, there is an example command (which is similar to what you gave as an example) in README.md:

# 1- changelog header is removed from CHANGELOG.md
# 2- new entries are prepended to CHANGELOG.md without footer part
git cliff --unreleased --tag 1.0.0 --prepend CHANGELOG.md

So I'm not sure if there is a problem here. Maybe you have a different use-case for --prepend? Feel free to submit another issue about this and I'd be more than happy to work on it šŸ™‚

P.S. Sorry for the late reply.