Skip to content

Commit

Permalink
Edge case: Empty message in the first commit (#217)
Browse files Browse the repository at this point in the history
Don't try to consume a 2nd new line when the first repository
commit has an empty message.
  • Loading branch information
claudiu-cristea committed May 7, 2024
1 parent 5a47e03 commit b9175ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Gitonomy/Git/Parser/LogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ protected function doParse()
$this->consumeGPGSignature();

$this->consumeNewLine();
$this->consumeNewLine();
if ($this->cursor < strlen($this->content)) {
$this->consumeNewLine();
}

$message = '';
if ($this->expects(' ')) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Gitonomy/Git/Tests/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,14 @@ public function testIterable($repository)
}
}
}

public function testFirstMessageEmpty()
{
$repository = $this->createEmptyRepository(false);
file_put_contents($repository->getWorkingDir().'/file', 'foo');
$repository->run('add', ['.']);
$repository->run('commit', ['--allow-empty-message', '--no-edit']);
$commits = $repository->getLog()->getCommits();
$this->assertCount(1, $commits);
}
}

0 comments on commit b9175ec

Please sign in to comment.