Skip to content

Commit fae9911

Browse files
authored
Skip third party unsupported headers. (#232)
* Skip third party unsupported headers. * Fix sniff remarks. * Sniffs fix v2.
1 parent de03597 commit fae9911

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/Gitonomy/Git/Parser/LogParser.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected function doParse()
5151
$this->consumeGPGSignature();
5252

5353
$this->consumeNewLine();
54+
$this->consumeUnsupportedLinesToNewLine();
5455
if ($this->cursor < strlen($this->content)) {
5556
$this->consumeNewLine();
5657
}
@@ -76,4 +77,15 @@ protected function doParse()
7677
$this->log[] = $commit;
7778
}
7879
}
80+
81+
protected function consumeUnsupportedLinesToNewLine()
82+
{
83+
// Consume any unsupported lines that may appear in the log output. For
84+
// example, gitbutler headers or other custom metadata but this should
85+
// work regardless of the content.
86+
while (!$this->isFinished() && substr($this->content, $this->cursor, 1) !== "\n") {
87+
$this->consumeTo("\n");
88+
$this->consumeNewLine();
89+
}
90+
}
7991
}

tests/Gitonomy/Git/Tests/LogTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace Gitonomy\Git\Tests;
1414

15+
use Gitonomy\Git\Parser\LogParser;
16+
1517
class LogTest extends AbstractTest
1618
{
1719
/**
@@ -91,4 +93,44 @@ public function testFirstMessageEmpty()
9193
$commits = $repository->getLog()->getCommits();
9294
$this->assertCount(1, $commits);
9395
}
96+
97+
public function testParsesCommitsWithAndWithoutGitButlerHeaders(): void
98+
{
99+
$logContent = <<<'EOT'
100+
commit 1111111111111111111111111111111111111111
101+
tree abcdefabcdefabcdefabcdefabcdefabcdefabcd
102+
author John Doe <[email protected]> 1620000000 +0000
103+
committer John Doe <[email protected]> 1620000000 +0000
104+
105+
First commit message
106+
107+
commit 2222222222222222222222222222222222222222
108+
tree abcdefabcdefabcdefabcdefabcdefabcdefabcd
109+
parent 1111111111111111111111111111111111111111
110+
author Jane Smith <[email protected]> 1620003600 +0000
111+
committer Jane Smith <[email protected]> 1620003600 +0000
112+
gitbutler-headers-version: 2
113+
gitbutler-change-id: a7bd485c-bae6-45b2-910f-163c78aace81
114+
115+
Commit with GitButler headers
116+
117+
commit 3333333333333333333333333333333333333333
118+
tree abcdefabcdefabcdefabcdefabcdefabcdefabcd
119+
author John Doe <[email protected]> 1620007200 +0000
120+
committer Jane Smith <[email protected]> 1620007200 +0000
121+
122+
Another commit without GitButler headers
123+
124+
EOT;
125+
126+
$parser = new LogParser();
127+
$parser->parse($logContent);
128+
129+
$log = $parser->log;
130+
$this->assertCount(3, $log);
131+
132+
$this->assertEquals("First commit message\n", $log[0]['message']);
133+
$this->assertEquals("Commit with GitButler headers\n", $log[1]['message']);
134+
$this->assertEquals("Another commit without GitButler headers\n", $log[2]['message']);
135+
}
94136
}

0 commit comments

Comments
 (0)