Skip to content

Commit

Permalink
feat: Strip prefix
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
JP-Ellis authored and epage committed Dec 18, 2024
1 parent 1b8f92e commit 724f1b8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/committed/src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, anyhow::Error> {
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 724f1b8

Please sign in to comment.