Skip to content

Commit b9175ec

Browse files
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.
1 parent 5a47e03 commit b9175ec

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Gitonomy/Git/Parser/LogParser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ protected function doParse()
4949
$this->consumeGPGSignature();
5050

5151
$this->consumeNewLine();
52-
$this->consumeNewLine();
52+
if ($this->cursor < strlen($this->content)) {
53+
$this->consumeNewLine();
54+
}
5355

5456
$message = '';
5557
if ($this->expects(' ')) {

tests/Gitonomy/Git/Tests/LogTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,14 @@ public function testIterable($repository)
7676
}
7777
}
7878
}
79+
80+
public function testFirstMessageEmpty()
81+
{
82+
$repository = $this->createEmptyRepository(false);
83+
file_put_contents($repository->getWorkingDir().'/file', 'foo');
84+
$repository->run('add', ['.']);
85+
$repository->run('commit', ['--allow-empty-message', '--no-edit']);
86+
$commits = $repository->getLog()->getCommits();
87+
$this->assertCount(1, $commits);
88+
}
7989
}

0 commit comments

Comments
 (0)