Skip to content

Commit 451a694

Browse files
lehmanjuorhun
andauthored
fix(submodules): fix submodules handling when using custom range (#1136)
* fix: first release wrong for submodules with custom range * refactor: Update git-cliff/src/lib.rs --------- Co-authored-by: Orhun Parmaksız <[email protected]>
1 parent cbeca6d commit 451a694

File tree

6 files changed

+126
-18
lines changed

6 files changed

+126
-18
lines changed

.github/fixtures/test-submodules-include-path/expected.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ All notable changes to this project will be documented in this file.
2222
- Submodule_two with initial commits
2323
- Submodule_two update 1
2424

25-
### Submodule_one
26-
27-
#### Bug Fixes
28-
29-
- Submodule_one fix A
30-
31-
#### Features
32-
33-
- Submodule_one feature A
34-
- Submodule_one initial commit
35-
36-
3725
### Submodule_two
3826

3927
#### Bug Fixes
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[changelog]
5+
# A Tera template to be rendered for each release in the changelog.
6+
# See https://keats.github.io/tera/docs/#introduction
7+
body = """
8+
{% if version %}\
9+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
10+
{% else %}\
11+
## [unreleased]
12+
{% endif %}\
13+
{% for group, commits in commits | group_by(attribute="group") %}
14+
### {{ group | upper_first }}
15+
{% for commit in commits %}
16+
- {{ commit.message | upper_first }}\
17+
{% endfor %}
18+
{% endfor %}\
19+
{% for submodule_path, commits in submodule_commits %}
20+
### {{ submodule_path | upper_first }}
21+
{% for group, commits in commits | group_by(attribute="group") %}
22+
#### {{ group | upper_first }}
23+
{% for commit in commits %}
24+
- {{ commit.message | upper_first }}\
25+
{% endfor %}
26+
{% endfor %}
27+
{% endfor %}\n
28+
"""
29+
30+
[git]
31+
# An array of regex based parsers for extracting data from the commit message.
32+
# Assigns commits to groups.
33+
# Optionally sets the commit's `scope` and can decide to exclude commits from further processing.
34+
commit_parsers = [
35+
{ message = "^feat", group = "Features", default_scope = "app" },
36+
{ message = "^fix", group = "Bug Fixes", scope = "cli" },
37+
]
38+
recurse_submodules = true
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
current_dir="$(pwd)"
5+
submodule_one_dir="$(mktemp -d)"
6+
submodule_two_dir="$(mktemp -d)"
7+
8+
cd $submodule_one_dir && git init >&2
9+
GIT_COMMITTER_DATE="2022-04-05 01:00:8" git commit --allow-empty -m "feat: submodule_one initial commit"
10+
11+
cd $submodule_two_dir && git init >&2
12+
GIT_COMMITTER_DATE="2022-04-05 01:00:12" git commit --allow-empty -m "feat: submodule_two feature B"
13+
14+
cd $current_dir
15+
GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
16+
17+
git -c protocol.file.allow=always submodule add $submodule_one_dir submodule_one
18+
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit -a -m "feat: add submodule_one"
19+
20+
cd submodule_one
21+
GIT_COMMITTER_DATE="2022-04-05 01:00:10" git commit --allow-empty -m "feat: submodule_one feature A"
22+
GIT_COMMITTER_DATE="2022-04-05 01:00:11" git commit --allow-empty -m "fix: submodule_one fix A"
23+
cd ..
24+
25+
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit -a -m "feat: submodule_one update 1"
26+
git tag v0.1.0
27+
28+
git -c protocol.file.allow=always submodule add $submodule_two_dir submodule_two
29+
GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit -a -m "feat: submodule_two with initial commits"
30+
31+
cd submodule_two
32+
GIT_COMMITTER_DATE="2022-04-05 01:00:13" git commit --allow-empty -m "fix: submodule_two fix B"
33+
cd ..
34+
35+
GIT_COMMITTER_DATE="2022-04-06 01:25:12" git commit -a -m "feat: submodule_two update 1"
36+
git tag v0.2.0
37+
38+
cd submodule_two
39+
GIT_COMMITTER_DATE="2022-04-05 01:00:14" git commit --allow-empty -m "fix: submodule_two fix C"
40+
cd ..
41+
42+
GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit -a -m "feat: submodule_two update 2"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [unreleased]
6+
7+
### Features
8+
9+
- Submodule_two update 2
10+
11+
### Submodule_two
12+
13+
#### Bug Fixes
14+
15+
- Submodule_two fix C
16+
17+
18+
## [0.2.0] - 2022-04-06
19+
20+
### Features
21+
22+
- Submodule_two with initial commits
23+
- Submodule_two update 1
24+
25+
### Submodule_two
26+
27+
#### Bug Fixes
28+
29+
- Submodule_two fix B
30+
31+
#### Features
32+
33+
- Submodule_two feature B
34+
35+
36+
<!-- generated by git-cliff -->

.github/workflows/test-fixtures.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ jobs:
117117
- fixtures-name: test-require-conventional-negative
118118
- fixtures-name: test-require-conventional-skipped
119119
- fixtures-name: test-submodules
120+
- fixtures-name: test-submodules-range
121+
command: v0.1.0..HEAD
120122
- fixtures-name: test-submodules-include-path
121123
command: --include-path submodule_two
122124
- fixtures-name: test-remote-config

git-cliff/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ fn process_submodules(
172172
.clone()
173173
.and_then(|commit_id| repository.find_commit(&commit_id));
174174

175+
trace!("Processing submodule commits in {first_commit:?}..{last_commit:?}");
176+
175177
// Query repository for submodule changes. For each submodule a
176178
// SubmoduleRange is created, describing the range of commits in the context
177179
// of that submodule.
@@ -388,12 +390,6 @@ fn process_repository<'a>(
388390
releases.last_mut().unwrap().previous = Some(Box::new(previous_release));
389391
}
390392

391-
if recurse_submodules {
392-
for release in &mut releases {
393-
process_submodules(repository, release, config.git.topo_order_commits)?;
394-
}
395-
}
396-
397393
if args.sort == Sort::Newest {
398394
for release in &mut releases {
399395
release.commits.reverse();
@@ -443,6 +439,12 @@ fn process_repository<'a>(
443439
}
444440
}
445441

442+
if recurse_submodules {
443+
for release in &mut releases {
444+
process_submodules(repository, release, config.git.topo_order_commits)?;
445+
}
446+
}
447+
446448
// Set custom message for the latest release.
447449
if let Some(message) = &args.with_tag_message {
448450
if let Some(latest_release) = releases

0 commit comments

Comments
 (0)