Skip to content

Commit

Permalink
fix: Deduplicate commits for unreleased version with merged branches
Browse files Browse the repository at this point in the history
PR-76: #76
  • Loading branch information
chme committed Mar 18, 2024
1 parent 92f6f94 commit b61199f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/git_changelog/build.py
Expand Up @@ -157,7 +157,7 @@ def add_commit(self, commit: Commit) -> None:
commit: The git commit.
"""
self.commits.append(commit)
commit.version = self.tag
commit.version = self.tag or "HEAD"
if commit_type := commit.convention.get("type"):
if commit_type not in self.sections_dict:
section = Section(section_type=commit_type)
Expand Down
38 changes: 38 additions & 0 deletions tests/test_build.py
Expand Up @@ -218,3 +218,41 @@ def test_no_remote_url(repo: GitRepo) -> None:
expected_prev_tag=None,
expected_commits=[commit_a],
)


def test_merge_into_unreleased(repo: GitRepo) -> None:
r"""Test parsing and grouping commits to versions.
Commit graph:
main A---C---E
\ / \ /
feat B D
Expected:
- Unreleased: E D C B A
Parameters:
repo: GitRepo to a temporary repository.
"""
commit_a = repo.first_hash
repo.branch("feat/1")
repo.checkout("feat/1")
commit_b = repo.commit("feat: B")
repo.checkout("main")
commit_c = repo.merge("feat/1")
repo.branch("feat/2")
repo.checkout("feat/2")
commit_d = repo.commit("feat: D")
repo.checkout("main")
commit_e = repo.merge("feat/2")

changelog = Changelog(repo.path, convention=AngularConvention)

assert len(changelog.versions_list) == 1
version = changelog.versions_list[0]
_assert_version(
version,
expected_tag="0.1.0",
expected_prev_tag=None,
expected_commits=[commit_e, commit_c, commit_d, commit_a, commit_b],
)

0 comments on commit b61199f

Please sign in to comment.