Skip to content

Commit 04d082f

Browse files
authored
chore: Fix regression in determining tag for conventional commits (#1133)
Co-authored-by: Dylan Anthony <[email protected]>
1 parent e672210 commit 04d082f

File tree

6 files changed

+18
-44
lines changed

6 files changed

+18
-44
lines changed

Diff for: crates/knope/src/integrations/git.rs

+7-25
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,6 @@ enum ErrorKind {
142142
help("A Git tag could not be created for the release.")
143143
)]
144144
CreateTagError(#[from] gix::tag::Error),
145-
#[error("Could not find reference {reference}: {source}")]
146-
#[diagnostic(
147-
code(releases::git::find_reference),
148-
help("Please check that the reference exists.")
149-
)]
150-
FindReference {
151-
reference: String,
152-
#[source]
153-
source: gix::reference::find::existing::Error,
154-
},
155145
#[error("Could not peel oid: {0}")]
156146
#[diagnostic(
157147
code(releases::git::peel_oid),
@@ -395,24 +385,16 @@ pub(crate) fn add_files(file_names: &[RelativePathBuf]) -> Result<(), Error> {
395385
/// means that there could be paths which jump _behind_ the target tag... and we want to exclude
396386
/// those as well. There's probably a way to optimize performance with some cool graph magic
397387
/// eventually, but this is good enough for now.
398-
pub(crate) fn get_commit_messages_after_tag(tag: Option<&str>) -> Result<Vec<String>, Error> {
388+
pub(crate) fn get_commit_messages_after_tag(tag: &str) -> Result<Vec<String>, Error> {
399389
let repo = gix::open(".")?;
400-
if let Some(tag) = &tag {
401-
debug!("Finding all commits since tag {tag}");
390+
391+
let reference = repo.find_reference(&format!("refs/tags/{tag}")).ok();
392+
if reference.is_some() {
393+
debug!("Using commits since tag {tag}");
402394
} else {
403-
debug!("Finding ALL commits");
395+
debug!("Tag {tag} not found, using ALL commits");
404396
}
405-
let commits_to_exclude = tag
406-
.map(|tag| format!("refs/tags/{tag}"))
407-
.as_ref()
408-
.map(|reference| {
409-
repo.find_reference(reference)
410-
.map_err(|err| ErrorKind::FindReference {
411-
reference: reference.clone(),
412-
source: err,
413-
})
414-
})
415-
.transpose()?
397+
let commits_to_exclude = reference
416398
.map(gix::Reference::into_fully_peeled_id)
417399
.transpose()?
418400
.and_then(|tag_oid| repo.find_object(tag_oid).ok().map(gix::Object::into_commit))
+3-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use knope_versioning::{
2-
package,
3-
semver::{PackageVersions, StableVersion},
4-
ReleaseTag,
5-
};
1+
use knope_versioning::{package, semver::PackageVersions, ReleaseTag};
62
use tracing::debug;
73

84
use crate::integrations::git::{self, get_commit_messages_after_tag};
@@ -20,11 +16,7 @@ pub(crate) fn get_conventional_commits_after_last_stable_version(
2016
debug!("Only checking commits with scopes: {scopes:?}");
2117
}
2218
let target_version = PackageVersions::from_tags(package_name.as_custom(), all_tags).stable();
23-
let tag = if target_version == StableVersion::default() {
24-
None
25-
} else {
26-
Some(ReleaseTag::new(&target_version.into(), package_name))
27-
};
19+
let tag = ReleaseTag::new(&target_version.into(), package_name);
2820

29-
get_commit_messages_after_tag(tag.as_ref().map(ReleaseTag::as_str)).map_err(git::Error::from)
21+
get_commit_messages_after_tag(tag.as_str()).map_err(git::Error::from)
3022
}

Diff for: crates/knope/tests/prepare_release/go_modules/major_version_directories/dryrun_stdout.log

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ No tags found matching pattern v2/v
1111
Getting conventional commits since last release of package v1
1212
Only checking commits with scopes: ["v1"]
1313
No tags found matching pattern v1/v
14-
Finding ALL commits
14+
Tag v1/v0.0.0 not found, using ALL commits
1515
Determining new version for v1
1616
commit fix(v1): A fix
1717
implies rule PATCH
@@ -32,7 +32,7 @@ Would add files to git:
3232
Getting conventional commits since last release of package v2
3333
Only checking commits with scopes: ["v2"]
3434
No tags found matching pattern v2/v
35-
Finding ALL commits
35+
Tag v2/v0.0.0 not found, using ALL commits
3636
Determining new version for v2
3737
commit feat(v2): New feature
3838
implies rule MINOR

Diff for: crates/knope/tests/prepare_release/go_modules/major_version_directories/stdout.log

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ No tags found matching pattern v2/v
1111
Getting conventional commits since last release of package v1
1212
Only checking commits with scopes: ["v1"]
1313
No tags found matching pattern v1/v
14-
Finding ALL commits
14+
Tag v1/v0.0.0 not found, using ALL commits
1515
Determining new version for v1
1616
commit fix(v1): A fix
1717
implies rule PATCH
1818
Using PATCH rule to bump from 1.0.0 to 1.0.1
1919
Getting conventional commits since last release of package v2
2020
Only checking commits with scopes: ["v2"]
2121
No tags found matching pattern v2/v
22-
Finding ALL commits
22+
Tag v2/v0.0.0 not found, using ALL commits
2323
Determining new version for v2
2424
commit feat(v2): New feature
2525
implies rule MINOR

Diff for: crates/knope/tests/prepare_release/verbose/dryrun_stdout.log

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package.json has version 0.4.6
77
Looking for Git tags matching package name.
88
Getting conventional commits since last release of package first
99
Only checking commits with scopes: ["first"]
10-
Finding all commits since tag first/v1.2.3
10+
Using commits since tag first/v1.2.3
1111
Determining new version for first
1212
commit feat: A feature
1313
implies rule MINOR
@@ -72,7 +72,7 @@ Would add files to git:
7272
FIRST_CHANGELOG.md
7373
Getting conventional commits since last release of package second
7474
Only checking commits with scopes: ["second"]
75-
Finding all commits since tag second/v0.4.6
75+
Using commits since tag second/v0.4.6
7676
Determining new version for second
7777
commit feat: A feature
7878
implies rule MINOR

Diff for: crates/knope/tests/prepare_release/verbose/stdout.log

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package.json has version 0.4.6
77
Looking for Git tags matching package name.
88
Getting conventional commits since last release of package first
99
Only checking commits with scopes: ["first"]
10-
Finding all commits since tag first/v1.2.3
10+
Using commits since tag first/v1.2.3
1111
Determining new version for first
1212
commit feat: A feature
1313
implies rule MINOR
@@ -34,7 +34,7 @@ changeset feature.md
3434
Using MAJOR rule to bump from 1.2.3 to 2.0.0
3535
Getting conventional commits since last release of package second
3636
Only checking commits with scopes: ["second"]
37-
Finding all commits since tag second/v0.4.6
37+
Using commits since tag second/v0.4.6
3838
Determining new version for second
3939
commit feat: A feature
4040
implies rule MINOR

0 commit comments

Comments
 (0)