Skip to content

Commit

Permalink
Merge pull request #40 from sebastianfeldmann/detect-squash-and-fixup…
Browse files Browse the repository at this point in the history
…-commits

Detect squash and fixup commits
  • Loading branch information
sebastianfeldmann authored Oct 23, 2022
2 parents b324b6b + c70b54c commit 14de823
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/CommitMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/git/CommitMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 14de823

Please sign in to comment.