From 6bb31ea5339bb785f6edcf387c8093fc9a8628cf Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Tue, 29 Sep 2026 12:03:49 +0200 Subject: [PATCH] chlog: add -f/--file to target a specific changelog The changelog path was hardcoded to debian/changelog in the series detection, the entry generation and the editor invocation. Packages keeping the changelog elsewhere (e.g. a staging copy) could not use chlog on it. Add -f/--file defaulting to debian/changelog, threaded through all three uses. The library side was already parameterized on the file, so no changelog.rs behavior changes beyond a test pinning the non-default path. --- README.md | 3 +++ src/changelog.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 11 ++++++++--- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aeace56..dc7e985 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,9 @@ pkh put --ppa user/hello_xxx git push xxx user-fork ``` +`pkh chlog` edits `debian/changelog` by default; point it at another file +with `--file ` (`-f`). + `pkh chlog` walks the commit history back to the previous changelog entry. Without a version tag, that search is capped at the last 500 commits (`--limit `, `0` = unlimited): beyond the cap, the entry simply starts diff --git a/src/changelog.rs b/src/changelog.rs index 4471e00..b425a4b 100644 --- a/src/changelog.rs +++ b/src/changelog.rs @@ -1363,6 +1363,52 @@ mod tests { assert!(!content.contains("* Initial commit")); } + /// A non-default changelog file (pkh chlog -f): the entry is + /// prepended to that file, and its version is parsed from it + #[tokio::test] + async fn test_generate_entry_custom_changelog_file() { + let temp_dir = TempDir::new().unwrap(); + let repo_dir = temp_dir.path(); + setup_repo(repo_dir); + + let changelog_path = repo_dir.join("debian/changelog.local"); + std::fs::create_dir_all(repo_dir.join("debian")).unwrap(); + std::fs::write( + &changelog_path, + "mypackage (0.1.0-1) unstable; urgency=medium\n\n * Initial release\n\n -- Maintainer Wed, 01 Jan 2020 00:00:00 +0000\n", + ) + .unwrap(); + + let _identity = IDENTITY_LOCK.lock().await; + unsafe { + std::env::set_var("DEBFULLNAME", "Maintainer Maintainer"); + std::env::set_var("DEBEMAIL", "maintainer@maintainer.com"); + } + let entry = generate_entry( + "debian/changelog.local", + Some(repo_dir), + None, + None, + EntryKind::Normal, + 0, + ) + .await + .unwrap(); + unsafe { + std::env::remove_var("DEBFULLNAME"); + std::env::remove_var("DEBEMAIL"); + } + + assert_eq!(entry.previous_version, "0.1.0-1"); + assert_eq!(entry.new_version, "0.1.0-2"); + let content = std::fs::read_to_string(&changelog_path).unwrap(); + assert!(content.starts_with("mypackage (0.1.0-2) unstable; urgency=medium")); + assert!(content.contains("mypackage (0.1.0-1) unstable; urgency=medium")); + + // The default file is not created next to it + assert!(!repo_dir.join("debian/changelog").exists()); + } + #[test] fn test_compute_new_version() { // Debian upload diff --git a/src/main.rs b/src/main.rs index fbe8024..905238f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -329,6 +329,7 @@ fn main() { .conflicts_with("rebuild")) .arg(arg!(--rebuild "Number the entry as a no-change rebuild (1.0-1 becomes 1.0-1build1)").required(false)) .arg(arg!(-v --version "Target version (overrides the --backport/--nmu/--rebuild numbering)").required(false)) + .arg(arg!(-f --file "Path to the changelog file to generate into and edit (default: debian/changelog)").required(false).default_value("debian/changelog")) .arg(arg!(--limit "Cap how far back the history is searched for the previous changelog entry when no version tag exists (0 = unlimited)").required(false) .value_parser(clap::value_parser!(usize)).default_value("500")), ) @@ -667,6 +668,10 @@ fn main() { .get_one::("limit") .copied() .unwrap_or(500); + let changelog_file = sub_matches + .get_one::("file") + .map(|s| s.to_string()) + .unwrap_or_else(|| "debian/changelog".to_string()); let cwd = current_dir_or_exit(); let version = sub_matches.get_one::("version").map(|s| s.as_str()); let cli_series = sub_matches.get_one::("series").map(|s| s.as_str()); @@ -692,7 +697,7 @@ fn main() { let target_series = if let Some(s) = cli_series { Some(s.to_string()) } else { - let changelog_path = cwd.join("debian/changelog"); + let changelog_path = cwd.join(&changelog_file); match rt.block_on(pkh::changelog::series_candidates(&changelog_path)) { Some(pkh::changelog::SeriesCandidates::Choose { options, @@ -720,7 +725,7 @@ fn main() { }; let entry = match rt.block_on(pkh::changelog::generate_entry( - "debian/changelog", + &changelog_file, Some(&cwd), version, target_series.as_deref(), @@ -752,7 +757,7 @@ fn main() { }; let _status = std::process::Command::new(&editor) .current_dir(&cwd) - .args(["debian/changelog"]) + .arg(&changelog_file) .status() .map_err(|e| { error!(