Skip to content

Commit 0853cb9

Browse files
Edge case: Empty message in the first commit (#217)
* 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
1 parent 5a47e03 commit 0853cb9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Gitonomy/Git/Parser/LogParser.php

+3-1
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

+15
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,19 @@ public function testIterable($repository)
7676
}
7777
}
7878
}
79+
80+
public function testFirstMessageEmpty()
81+
{
82+
$repository = $this->createEmptyRepository(false);
83+
$repository->run('config', ['--local', 'user.name', '"Unit Test"']);
84+
$repository->run('config', ['--local', 'user.email', '"[email protected]"']);
85+
86+
// Edge case: first commit lacks a message.
87+
file_put_contents($repository->getWorkingDir().'/file', 'foo');
88+
$repository->run('add', ['.']);
89+
$repository->run('commit', ['--allow-empty-message', '--no-edit']);
90+
91+
$commits = $repository->getLog()->getCommits();
92+
$this->assertCount(1, $commits);
93+
}
7994
}

0 commit comments

Comments
 (0)