diff --git a/Cargo.lock b/Cargo.lock index 7bea7b7..45bc6b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -174,6 +174,7 @@ dependencies = [ "log", "pulldown-cmark", "semver", + "testing_logger", "toml_edit 0.21.1", "winnow 0.5.40", ] @@ -2119,6 +2120,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "testing_logger" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d92b727cb45d33ae956f7f46b966b25f1bc712092aeef9dba5ac798fc89f720" +dependencies = [ + "log", +] + [[package]] name = "thiserror" version = "1.0.63" diff --git a/Cargo.toml b/Cargo.toml index 56df9d3..f5ba84f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,5 +43,6 @@ bitflags = "2" [dev-dependencies] insta = "1.8.0" gix-testtools = "0.15.0" +testing_logger = "0.1.1" [workspace] diff --git a/src/cli/main.rs b/src/cli/main.rs index 7934243..f8774d6 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -63,6 +63,7 @@ fn main() -> anyhow::Result<()> { no_isolate_dependencies_from_breaking_changes, capitalize_commit, registry, + signoff, } => { let verbose = execute || verbose; init_logging(verbose); @@ -91,6 +92,7 @@ fn main() -> anyhow::Result<()> { allow_changelog_github_release: !no_changelog_github_release, capitalize_commit, registry, + signoff, }, crates, to_bump_spec(bump.as_deref().unwrap_or(DEFAULT_BUMP_SPEC))?, diff --git a/src/cli/options.rs b/src/cli/options.rs index a784195..510889c 100644 --- a/src/cli/options.rs +++ b/src/cli/options.rs @@ -165,6 +165,10 @@ pub enum SubCommands { /// Capitalize commit messages. #[clap(long, help_heading = Some("CHANGELOG"))] capitalize_commit: bool, + + /// Sign off commit messages. + #[clap(long, help_heading = Some("CUSTOMIZATION"))] + signoff: bool, }, #[clap(name = "changelog", version = option_env!("CARGO_SMART_RELEASE_VERSION"))] /// Generate changelogs from commit histories, non-destructively. diff --git a/src/command/mod.rs b/src/command/mod.rs index 13cbd7f..7d68e25 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -27,6 +27,7 @@ pub mod release { pub allow_changelog_github_release: bool, pub capitalize_commit: bool, pub registry: Option, + pub signoff: bool, } } #[path = "release/mod.rs"] diff --git a/src/command/release/git.rs b/src/command/release/git.rs index b280d9c..f15d1be 100644 --- a/src/command/release/git.rs +++ b/src/command/release/git.rs @@ -11,6 +11,7 @@ pub(in crate::command::release_impl) fn commit_changes( message: impl AsRef, dry_run: bool, empty_commit_possible: bool, + signoff: bool, ctx: &crate::Context, ) -> anyhow::Result>> { // TODO: replace with gitoxide one day @@ -19,6 +20,9 @@ pub(in crate::command::release_impl) fn commit_changes( if empty_commit_possible { cmd.arg("--allow-empty"); } + if signoff { + cmd.arg("--signoff"); + } log::trace!("{} run {:?}", will(dry_run), cmd); if dry_run { return Ok(None); @@ -115,3 +119,54 @@ pub fn push_tags_and_head( bail!("'git push' invocation failed. Try to push manually and repeat the smart-release invocation to resume, possibly with --skip-push."); } } + +#[cfg(test)] +mod tests { + use log::Level; + + use super::*; + + #[test] + fn test_commit_changes() { + let ctx = crate::Context::new( + vec![], + false, + crate::version::BumpSpec::Auto, + crate::version::BumpSpec::Auto, + ) + .unwrap(); + let message = "commit message"; + testing_logger::setup(); + let _ = commit_changes(message, true, false, false, &ctx).unwrap(); + testing_logger::validate(|captured_logs| { + assert_eq!(captured_logs.len(), 1); + assert_eq!( + captured_logs[0].body, + "WOULD run \"git\" \"commit\" \"-am\" \"commit message\"" + ); + assert_eq!(captured_logs[0].level, Level::Trace); + }); + } + + #[test] + fn test_commit_changes_with_signoff() { + let ctx = crate::Context::new( + vec![], + false, + crate::version::BumpSpec::Auto, + crate::version::BumpSpec::Auto, + ) + .unwrap(); + let message = "commit message"; + testing_logger::setup(); + let _ = commit_changes(message, true, false, true, &ctx).unwrap(); + testing_logger::validate(|captured_logs| { + assert_eq!(captured_logs.len(), 1); + assert_eq!( + captured_logs[0].body, + "WOULD run \"git\" \"commit\" \"-am\" \"commit message\" \"--signoff\"" + ); + assert_eq!(captured_logs[0].level, Level::Trace); + }); + } +} diff --git a/src/command/release/manifest.rs b/src/command/release/manifest.rs index 9494118..0bb50dc 100644 --- a/src/command/release/manifest.rs +++ b/src/command/release/manifest.rs @@ -102,7 +102,7 @@ pub(in crate::command::release_impl) fn edit_version_and_fixup_dependent_crates_ opts.clone(), )?; - let res = git::commit_changes(commit_message, dry_run, !made_change, &ctx.base)?; + let res = git::commit_changes(commit_message, dry_run, !made_change, opts.signoff, &ctx.base)?; if let Some(bail_message) = bail_message { bail!(bail_message); } else {