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
* Edge case: Empty message in the first commit (#217)

Don't try to consume a 2nd new line when the first repository
commit has an empty message.

* Ensure author identity
  • Loading branch information
claudiu-cristea committed May 7, 2024
1 parent 5a47e03 commit 0853cb9
Show file tree
Hide file tree
Showing 2 changed files with 18 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
15 changes: 15 additions & 0 deletions tests/Gitonomy/Git/Tests/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,19 @@ public function testIterable($repository)
}
}
}

public function testFirstMessageEmpty()
{
$repository = $this->createEmptyRepository(false);
$repository->run('config', ['--local', 'user.name', '"Unit Test"']);
$repository->run('config', ['--local', 'user.email', '"unit_test@unit-test.com"']);

// Edge case: first commit lacks a message.
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 0853cb9

Please sign in to comment.