From 3068f40b5150d7a6f58bb5446d841d96446a39e1 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Thu, 19 Sep 2024 17:23:40 +1000 Subject: [PATCH] feat: strip prefix If fixups are allowed, then the remainder of the commit message ought to either be either a previous commit's subject line, or a hash: > If a commit message starts with "squash! ", "fixup! " or "amend! ", > the remainder of the subject line is taken as a commit specifier, > which matches a previous commit if it matches the subject line or the > hash of that commit. So we can either: 1. Assume that previous commit's subject line was previously validated and do nothing further; or, 2. Validate the remainder of the commit's subject line as is. This specific implementation opts for the latter. Signed-off-by: JP-Ellis --- crates/committed/src/checks.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/committed/src/checks.rs b/crates/committed/src/checks.rs index c7ee999..0a19f37 100644 --- a/crates/committed/src/checks.rs +++ b/crates/committed/src/checks.rs @@ -3,7 +3,7 @@ use committed::Style; pub(crate) fn check_message( source: report::Source<'_>, - message: &str, + mut message: &str, config: &crate::config::Config, report: report::Report, ) -> Result { @@ -19,6 +19,7 @@ pub(crate) fn check_message( } if config.no_fixup() { failed |= check_fixup(source, message, report)?; + message = strip_fixup(message); } // Bail out due to above checks if failed { @@ -356,6 +357,14 @@ pub(crate) fn check_fixup( } } +pub(crate) fn strip_fixup(message: &str) -> &str { + if let Some(message) = message.strip_prefix("fixup! ") { + message + } else { + message + } +} + pub(crate) fn check_merge_commit( source: report::Source<'_>, commit: &git2::Commit<'_>,