Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to signoff git commits #32

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ bitflags = "2"
[dev-dependencies]
insta = "1.8.0"
gix-testtools = "0.15.0"
testing_logger = "0.1.1"

[workspace]
2 changes: 2 additions & 0 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))?,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod release {
pub allow_changelog_github_release: bool,
pub capitalize_commit: bool,
pub registry: Option<String>,
pub signoff: bool,
}
}
#[path = "release/mod.rs"]
Expand Down
55 changes: 55 additions & 0 deletions src/command/release/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(in crate::command::release_impl) fn commit_changes(
message: impl AsRef<str>,
dry_run: bool,
empty_commit_possible: bool,
signoff: bool,
ctx: &crate::Context,
) -> anyhow::Result<Option<Id<'_>>> {
// TODO: replace with gitoxide one day
Expand All @@ -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);
Expand Down Expand Up @@ -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);
});
}
}
2 changes: 1 addition & 1 deletion src/command/release/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading