Skip to content

Commit

Permalink
feat: check all autosquash messages
Browse files Browse the repository at this point in the history
Expand the autosquash prefixes from just `fixup!` to now include
`squash!` and `amend!`. These are the prefixes supported by default when
using [Git's
`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash).

Signed-off-by: JP-Ellis <[email protected]>
  • Loading branch information
JP-Ellis committed Sep 19, 2024
1 parent c982cc9 commit b458f39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions crates/committed/src/checks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::report;
use committed::Style;

const AUTOSQUASH_PREFIXES: [&str; 3] = ["fixup! ", "squash! ", "amend! "];

pub(crate) fn check_message(
source: report::Source<'_>,
message: &str,
Expand All @@ -18,7 +20,7 @@ pub(crate) fn check_message(
failed |= check_wip(source, message, report)?;
}
if config.no_fixup() {
failed |= check_fixup(source, message, report)?;
failed |= check_autosquash(source, message, report)?;
}
// Bail out due to above checks
if failed {
Expand Down Expand Up @@ -313,13 +315,13 @@ pub(crate) fn check_wip(
}
}

pub(crate) fn check_fixup(
pub(crate) fn check_autosquash(
source: report::Source<'_>,
message: &str,
report: report::Report,
) -> Result<bool, anyhow::Error> {
if message.starts_with("fixup! ") {
report(report::Message::error(source, report::Fixup {}));
if AUTOSQUASH_PREFIXES.iter().any(|prefix| message.starts_with(prefix)) {
report(report::Message::error(source, report::Autosquash {}));
Ok(true)
} else {
Ok(false)
Expand Down
4 changes: 2 additions & 2 deletions crates/committed/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(crate) enum Content<'s> {
NoPunctuation(NoPunctuation),
Imperative(Imperative<'s>),
Wip(Wip),
Fixup(Fixup),
Autosquash(Autosquash),
InvalidCommitFormat(InvalidCommitFormat),
DisallowedCommitType(DisallowedCommitType),
MergeCommitDisallowed(MergeCommitDisallowed),
Expand Down Expand Up @@ -129,7 +129,7 @@ pub(crate) struct Wip {}
#[serde(rename_all = "snake_case")]
#[derive(derive_more::Display)]
#[display("Fixup commits must be squashed")]
pub(crate) struct Fixup {}
pub(crate) struct Autosquash {}

#[derive(Debug, serde::Serialize)]
#[serde(rename_all = "snake_case")]
Expand Down

0 comments on commit b458f39

Please sign in to comment.