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.
This commit is contained in:
@@ -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 <path>` (`-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 <n>`, `0` = unlimited): beyond the cap, the entry simply starts
|
||||
|
||||
@@ -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 <m@e.com> 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
|
||||
|
||||
+8
-3
@@ -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 <version> "Target version (overrides the --backport/--nmu/--rebuild numbering)").required(false))
|
||||
.arg(arg!(-f --file <path> "Path to the changelog file to generate into and edit (default: debian/changelog)").required(false).default_value("debian/changelog"))
|
||||
.arg(arg!(--limit <n> "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::<usize>("limit")
|
||||
.copied()
|
||||
.unwrap_or(500);
|
||||
let changelog_file = sub_matches
|
||||
.get_one::<String>("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::<String>("version").map(|s| s.as_str());
|
||||
let cli_series = sub_matches.get_one::<String>("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!(
|
||||
|
||||
Reference in New Issue
Block a user