Skip to content

Commit 4163526

Browse files
authored
Fix commit and tag resolution with branching histories (#574)
1 parent b7e2c44 commit 4163526

29 files changed

Lines changed: 528 additions & 117 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
default: patch
3+
---
4+
5+
#### Consistent commit selection in branching histories
6+
7+
PR #574 fixes issue #505 from @BatmanAoD.
8+
9+
Previous versions of Knope did not handle branching histories correctly. In some cases, this could result in commits from previous stable releases being included in a new release. It could _also_ result in missing some commits that _should_ have been included. This has been fixed—Knope should provide you the same commit list that `git rev-list {previous_stable_tag}..HEAD` would.

.changeset/fix_tag_resolution.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
default: major
3+
---
4+
5+
#### Ignore unreachable tags when determining version
6+
7+
PR #574 fixes issue #505 from @BatmanAoD.
8+
9+
Previously, the latests tags were always used to determine the current version, **even if those tags were not reachable from `HEAD`**. Now, only reachable tags will be considered. Use the `--verbose` flag to see tags which are being ignored.

Cargo.lock

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ clap = { version = "4.4.3", features = ["cargo", "string", "env"] }
2929
itertools = "0.11.0"
3030
miette = { version = "5.10.0", features = ["fancy"] }
3131
thiserror = "1.0.48"
32-
gix = { version = "0.53.1", default-features = false }
32+
gix = { version = "0.53.1", default-features = false, features = [
33+
"max-performance-safe",
34+
] }
3335
log = "0.4.20"
3436
env_logger = "0.10.0"
3537
indexmap = { version = "2.0.0", features = ["serde"] }

src/command.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use serde::{Deserialize, Serialize};
77
use crate::{
88
git::branch_name_from_issue,
99
releases::{package, semver},
10-
state, RunType, State,
10+
state,
11+
workflow::Verbose,
12+
RunType, State,
1113
};
1214

1315
/// Describes a value that you can replace an arbitrary string with when running a command.
@@ -26,13 +28,14 @@ pub(crate) fn run_command(
2628
mut run_type: RunType,
2729
mut command: String,
2830
variables: Option<HashMap<String, Variable>>,
31+
verbose: Verbose,
2932
) -> Result<RunType, Error> {
3033
let (state, dry_run_stdout) = match &mut run_type {
3134
RunType::DryRun { state, stdout } => (state, Some(stdout)),
3235
RunType::Real(state) => (state, None),
3336
};
3437
if let Some(variables) = variables {
35-
command = replace_variables(command, variables, state)?;
38+
command = replace_variables(command, variables, state, verbose)?;
3639
}
3740
if let Some(stdout) = dry_run_stdout {
3841
writeln!(stdout, "Would run {command}")?;
@@ -87,6 +90,7 @@ fn replace_variables(
8790
mut command: String,
8891
variables: HashMap<String, Variable>,
8992
state: &State,
93+
verbose: Verbose,
9094
) -> Result<String, Error> {
9195
for (var_name, var_type) in variables {
9296
match var_type {
@@ -102,7 +106,7 @@ fn replace_variables(
102106
release.new_version.to_string()
103107
} else {
104108
package
105-
.get_version()?
109+
.get_version(verbose)?
106110
.into_latest()
107111
.ok_or(Error::NoCurrentVersion)?
108112
.to_string()
@@ -135,6 +139,7 @@ mod test_run_command {
135139
RunType::Real(State::new(None, None, Vec::new())),
136140
command.clone(),
137141
None,
142+
Verbose::No,
138143
);
139144

140145
assert!(result.is_ok());
@@ -145,6 +150,7 @@ mod test_run_command {
145150
RunType::Real(State::new(None, None, Vec::new())),
146151
command,
147152
None,
153+
Verbose::No,
148154
);
149155
assert!(result.is_err());
150156
}
@@ -159,6 +165,7 @@ mod test_replace_variables {
159165
issues::Issue,
160166
releases::{semver::Version, Package, Release},
161167
state,
168+
workflow::Verbose,
162169
};
163170

164171
fn packages() -> Vec<Package> {
@@ -188,14 +195,14 @@ mod test_replace_variables {
188195
packages: packages(),
189196
};
190197

191-
let command = replace_variables(command, variables, &state).unwrap();
198+
let command = replace_variables(command, variables, &state, Verbose::No).unwrap();
192199

193200
assert_eq!(
194201
command,
195202
format!(
196203
"blah {} {}",
197204
&state.packages[0]
198-
.get_version()
205+
.get_version(Verbose::No)
199206
.unwrap()
200207
.into_latest()
201208
.unwrap(),
@@ -211,14 +218,14 @@ mod test_replace_variables {
211218
variables.insert("$$".to_string(), Variable::Version);
212219
let state = State::new(None, None, packages());
213220

214-
let command = replace_variables(command, variables, &state).unwrap();
221+
let command = replace_variables(command, variables, &state, Verbose::No).unwrap();
215222

216223
assert_eq!(
217224
command,
218225
format!(
219226
"blah {} other blah",
220227
&state.packages[0]
221-
.get_version()
228+
.get_version(Verbose::No)
222229
.unwrap()
223230
.into_latest()
224231
.unwrap(),
@@ -235,7 +242,7 @@ mod test_replace_variables {
235242
let version = Version::new(1, 2, 3, None);
236243
state.packages[0].prepared_release = Some(Release::new(None, version.clone()));
237244

238-
let command = replace_variables(command, variables, &state).unwrap();
245+
let command = replace_variables(command, variables, &state, Verbose::No).unwrap();
239246

240247
assert_eq!(command, format!("blah {version} other blah"));
241248
}
@@ -258,7 +265,7 @@ mod test_replace_variables {
258265
packages: Vec::new(),
259266
};
260267

261-
let command = replace_variables(command, variables, &state).unwrap();
268+
let command = replace_variables(command, variables, &state, Verbose::No).unwrap();
262269

263270
assert_eq!(command, format!("blah {expected_branch_name} other blah"));
264271
}

0 commit comments

Comments
 (0)