Skip to content

Commit 37ad030

Browse files
committed
minor #109 Fix GPG signed commits breaks parsing of commit messages (stojg)
This PR was merged into the 1.0-dev branch. Discussion ---------- Fix GPG signed commits breaks parsing of commit messages If commits are [signed gpg](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work) they will break the parsing of the log message since it's expecting two newlines after the commiter date where in the case of a GPG signature is added: Example commit: ``` commit e1a83f16ed61ae3807e5652c7ef894692c813513 tree 90908bdccbb0b9c42fdb6225d5aa47d7c66c3d22 parent 583811146f79f1bf6e167d54b276e21553512d1a author Stig Lindqvist <[email protected]> 1461274840 +1200 committer Stig Lindqvist <[email protected]> 1461274840 +1200 gpgsig -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJXGUjZAAoJEF7kfUZDyWQIaUkIAMYsSKA2C3XOQ2x0Ig3zOF5Y DV1YlSWa2ILy/V49U55CWMP/Atbr1bKpREMI9y1T9tBwsMV1gtqYk+JwqyCntTjD iaFexti++AZv47YrQa4aBtW18hRJp/BFrLjhkGnydHLvK1QJ2EAhIuqwRYiMHS8m mX3ChT1Quk5yZFumpPduGqwdNVWDxCssNMA6MKjn/gBWV1PUbsZWN2a9I54v7xfR ujKvzqwsnkKhOC4+0sQM25sw0AHj2/pqhAmB7tW+mjcUBY911ym7f1SvAMdrdMHm S5AJ0RkrntFqUA1Ydc6om+zUCSB8ztuNbD4JK5YrqukEy2ooyehWs8qc1NNLVLQ= =4KdG -----END PGP SIGNATURE----- signed commit ``` This PR is the quick solution by consuming the GPGSig (if it exists) and then throw it away. I added a test for this, but had to use my own [fork to create a signed commit](https://github.com/stojg/foobar/commit/e1a83f16ed61ae3807e5652c7ef894692c813513), so the tests will obviously fail unless the AbstractTest Repo is changed to `const REPOSITORY_URL = 'http://github.com/stojg/foobar.git';` This should fix #108 Commits ------- ab21ff6 Fix GPG signed commits breaks parsing of commit messages
2 parents 6e0c86f + ab21ff6 commit 37ad030

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)