Skip to content

Commit

Permalink
feat: Support all autosquash prefixes
Browse files Browse the repository at this point in the history
Committed, until now, only supported the `fixup!` prefix. The standard
Git implementation of `--autosquash` also supports `squash!` and
`amend!`. This commit modifies the logic of the handling of `fixup!` to
support the other two prefixes in the same way.

Note that this purely changes the logic. Function names and options
remain unchanged to ensure backwards compatibility. It may be worth
considering renaming this to `autosquash` given it is motivated
primarily by Git's `--autosquash` flag.

Ref: 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 Dec 19, 2024
1 parent 71a6c60 commit 30ff2c6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions crates/committed/src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,17 @@ pub(crate) fn check_wip(
}
}

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

pub(crate) fn check_fixup(
source: report::Source<'_>,
message: &str,
report: report::Report,
) -> Result<bool, anyhow::Error> {
if message.starts_with(FIXUP_PREFIX) {
if FIXUP_PREFIXES
.iter()
.any(|prefix| message.starts_with(prefix))
{
report(report::Message::error(source, report::Fixup {}));
Ok(true)
} else {
Expand All @@ -358,15 +363,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
for prefix in FIXUP_PREFIXES.iter() {
if let Some(message) = message.strip_prefix(prefix) {
return message;
}
}
message
}

const FIXUP_PREFIX: &str = "fixup! ";

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

0 comments on commit 30ff2c6

Please sign in to comment.