changelog: allow writing changelog in a non-git package
All checks were successful
CI / build (push) Successful in 3m0s

This commit is contained in:
2025-12-01 14:24:12 +01:00
parent 5c7b20f847
commit 49f0ff004e

View File

@@ -19,26 +19,22 @@ pub fn generate_entry(
Path::new(changelog_file).to_path_buf() Path::new(changelog_file).to_path_buf()
}; };
// 1. Parse existing changelog to get current (old) version // Parse existing changelog to get current (old) version
let (package, old_version, series) = parse_changelog_header(&changelog_path)?; let (package, old_version, series) = parse_changelog_header(&changelog_path)?;
println!("Found package: {}, version: {}", package, old_version); println!("Found package: {}, version: {}", package, old_version);
// 2. Open git repo // Open git repo, and find commits since last version tag
let repo_path = if let Some(path) = cwd { let repo_path = if let Some(path) = cwd {
path.to_path_buf() path.to_path_buf()
} else { } else {
std::env::current_dir()? std::env::current_dir()?
}; };
let repo = Repository::open(&repo_path)?; let commits = match Repository::open(&repo_path) {
Ok(repo) => get_commits_since_version(&repo, &old_version)?,
// 3. Find commits since the tag corresponding to the version // If there is no git repo (e.g. package downloaded from archive),
// we just generate an empty list of changes
let commits = get_commits_since_version(&repo, &old_version)?; Err(_e) => Vec::new(),
};
if commits.is_empty() {
println!("No new commits found since version {}", old_version);
// return Ok(());
}
// Compute new version if needed, or use user-supplied one // Compute new version if needed, or use user-supplied one
let new_version = if let Some(version) = user_version { let new_version = if let Some(version) = user_version {