From 724f1b8bca7abaa4ba34c47378ee1950f1e965c7 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 9b426b8..3a0fd79 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_PREFIX) { + message + } else { + message + } +} + const FIXUP_PREFIX: &str = "fixup! "; pub(crate) fn check_merge_commit(