What's new in 0.5.0?
In this post, I'm explaining the new features in the 0.5.0 release while giving insight into the different use-cases.
git-cliff is a command-line tool (written in Rust) that provides a highly customizable way to generate changelogs from git history. It supports using custom regular expressions to alter changelogs which are mostly based on conventional commits. With a single configuration file, a wide variety of formats can be applied for a changelog, thanks to the Jinja2/Django-inspired template engine. More information and examples can be found in the GitHub repository.
Today I released the new version (0.5.0) of git-cliff
. There are a couple of major features that I believe are interesting and they can potentially help with different use cases. Must be exciting, let's have a look!
What's new?β
--topo-order
β
--topo-order : Sorts the tags topologically
Imagine you are working on parallel code lines and you have the following git history:
* 0000025 (tag: v0.1.1, fix_v1) fix: patch on v0.1.x
| * 0000050 (HEAD -> master) feat: fifth commit on master
| * 0000040 (tag: v0.2.0) feat: fourth commit on master
| * 0000030 chore: third commit on master
|/
* 0000020 (tag: v0.1.0) fix: second commit on master
* 0000010 feat: first commit on master
In this scenario, we can pretend that after your fifth commit on master
you had to fix something about v0.1.0
and check out a new branch (fix_v1
). After that, you committed a patch and created a new tag. (v0.1.1
)
Now let's say you decided to generate a changelog for the unreleased commits. Since previous versions of git-cliff
sort the tags chronologically as default, you would get something like this:
$ git cliff --unreleased
# Changelog
## [unreleased]
### Features
- Fifth commit on master
## [0.2.0] - 2021-10-22
### Features
- Fourth commit on master
### Miscellaneous Tasks
- Third commit on master
This is because --unreleased
flag implicitly uses a commit range such as 0000025..HEAD
, since it sorts the tags chronologically, as previously stated. This situation can now be prevented by using the --topo-order
flag, which disables the automatic sorting and processes the tags as they appear in the git history:
$ git cliff --topo-order --unreleased
# Changelog
## [unreleased]
### Features
- Fifth commit on master
Now, the correct range of commits (0000040..HEAD
) is processed. In other words, v0.2.0
is accepted as the latest tag in the master
branch.
Tracking issue: #29
--include-path
&& --exclude-path
β
--include-path <PATTERN>... : Sets the path to include related commits
--exclude-path <PATTERN>... : Sets the path to exclude related commits
Let's say you have a monorepo and you want to generate a changelog that includes or excludes some commits that concern certain files/directories in the working directory. To explain it further, let's think that you have the following directory structure:
Cargo.toml
apps/
βββ application-related files
libs/
βββ library files
other/
βββ miscellaneous files
In the previous versions of git-cliff
, it was possible to only include commits in the changelog if the changes are against a path under e.g. "apps". This could be done by using the --commit-path
argument. But now, functionality is extended much further and you can specify multiple paths, use glob patterns and even exclude files/directories by using the brand new --include-path
and --exclude-path
arguments.
# include commits related to any TOML file and also application directory
$ git cliff --include-path "**/*.toml" --include-path "apps/*"
# exclude commits that are related to miscellaneous files
$ git cliff --exclude-path "other/*"
With this change, --commit-path
argument is removed replaced with --include-path
which supports glob patterns.
Tracking issue: #34
--current
β
--current: Processes the commits that belong to the current tag
Let's suppose this situation:
- First,
v0.10.0
is released. - After that,
v0.11.0
is released. - After that, a bug was found and
v0.10.1
is released.
The problem is was, when you check out to a tag and try to generate a changelog for the latest tag, it always points out to the most recent tag (which is v0.10.1
in our example). So how do you generate changelog for the currently checked out tag? Well, simple:
$ git checkout v0.11.0
# changelog is generated for v0.11.0
$ git cliff --current
# changelog is generated for v0.10.1
$ git cliff --latest
--current
flag behaves the same as running the following git command:
$ git describe --tags $(git rev-parse HEAD)
So it is expected to always use the current tag if it exists.
Tracking issue: #37