Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check all autosquash messages #395

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}));
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated to this commit and is a breaking change as discussed on the other PRs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, my expectation is this commit will continue to emit Fixup

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
Loading