Skip to content

Commit ab21ff6

Browse files
author
Stig Lindqvist
committed
Fix GPG signed commits breaks parsing of commit messages
1 parent 6e0c86f commit ab21ff6

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Gitonomy/Git/Parser/LogParser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ protected function doParse()
4343
$this->consume('committer ');
4444
list($commit['committerName'], $commit['committerEmail'], $commit['committerDate']) = $this->consumeNameEmailDate();
4545
$commit['committerDate'] = $this->parseDate($commit['committerDate']);
46+
47+
// will consume an GPG signed commit if there is one
48+
$this->consumeGPGSignature();
49+
4650
$this->consumeNewLine();
4751
$this->consumeNewLine();
4852

src/Gitonomy/Git/Parser/ParserBase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,19 @@ protected function consumeNewLine()
119119
{
120120
return $this->consume("\n");
121121
}
122+
123+
/**
124+
* @return string
125+
*/
126+
protected function consumeGPGSignature() {
127+
$expected = "\ngpgsig ";
128+
$length = strlen($expected);
129+
$actual = substr($this->content, $this->cursor, $length);
130+
if($actual != $expected) {
131+
return '';
132+
}
133+
$this->cursor += $length;
134+
135+
return $this->consumeTo("\n\n");
136+
}
122137
}

tests/Gitonomy/Git/Tests/AbstractTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ abstract class AbstractTest extends \PHPUnit_Framework_TestCase
2424
const INITIAL_COMMIT = '74acd054c8ec873ae6be044041d3a85a4f890ba5';
2525
const MERGE_COMMIT = '2f5b9d0a4e6e7173d7816e417805709c708674f8';
2626
const ENCODING_COMMIT = '779420b9b936f18a0b6579e1499a85b14270802e';
27+
const SIGNED_COMMIT = 'e1a83f16ed61ae3807e5652c7ef894692c813513';
2728

2829
/**
2930
* Local clone of remote URL. Avoids network call on each test.

tests/Gitonomy/Git/Tests/PushReferenceTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ public function testLog($repository)
5555
$this->assertEquals('add a long file', $log[0]->getShortMessage(), 'First commit is correct');
5656
}
5757

58+
/**
59+
* This test ensures that GPG signed requests does not break the reading of commit logs.
60+
*
61+
* @dataProvider provideFoobar
62+
*/
63+
public function testSignedLog($repository)
64+
{
65+
$ref = new PushReference($repository, 'foo', self::INITIAL_COMMIT, self::SIGNED_COMMIT);
66+
$log = $ref->getLog()->getCommits();
67+
$this->assertEquals(16, count($log), '16 commits in log');
68+
$this->assertEquals('signed commit', $log[0]->getShortMessage(), 'Last commit is correct');
69+
}
70+
5871
/**
5972
* @dataProvider provideFoobar
6073
*/

0 commit comments

Comments
 (0)