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 committed Dec 18, 2024
1 parent 8ac2dfd commit 3068f40
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! ") {
message
} else {
message
}
}

pub(crate) fn check_merge_commit(
source: report::Source<'_>,
commit: &git2::Commit<'_>,
Expand Down

0 comments on commit 3068f40

Please sign in to comment.