From c70b54c21b23eb01edf17ef376ecccb81665e041 Mon Sep 17 00:00:00 2001 From: Sebastian Feldmann Date: Sun, 23 Oct 2022 13:25:21 +0200 Subject: [PATCH] Detect squash and fixup commits --- src/CommitMessage.php | 19 +++++++++++++++++++ tests/git/CommitMessageTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/CommitMessage.php b/src/CommitMessage.php index 965c3ce..913729b 100644 --- a/src/CommitMessage.php +++ b/src/CommitMessage.php @@ -109,6 +109,25 @@ public function isEmpty(): bool return empty($this->content); } + /** + * Is this a fixup commit + * + * @return bool + */ + public function isFixup(): bool + { + return strpos($this->rawContent, 'fixup!') === 0; + } + + /** + * Is this a squash commit + * + * @return bool + */ + public function isSquash(): bool + { + return strpos($this->rawContent, 'squash!') === 0; + } /** * Get commit message content diff --git a/tests/git/CommitMessageTest.php b/tests/git/CommitMessageTest.php index 903051d..1f0a066 100644 --- a/tests/git/CommitMessageTest.php +++ b/tests/git/CommitMessageTest.php @@ -33,6 +33,30 @@ public function testIsEmpty() $this->assertTrue($msg->isEmpty()); } + /** + * Tests CommitMessage::isFixup + */ + public function testIsFixup() + { + $msg = new CommitMessage('Some stuff'); + $this->assertFalse($msg->isFixup()); + + $msg = new CommitMessage('fixup! Some stuff'); + $this->assertTrue($msg->isFixup()); + } + + /** + * Tests CommitMessage::isSquash + */ + public function testIsSquash() + { + $msg = new CommitMessage('Some stuff'); + $this->assertFalse($msg->isSquash()); + + $msg = new CommitMessage('squash! Some stuff'); + $this->assertTrue($msg->isSquash()); + } + /** * Tests CommitMessage::getSubject */