Skip to content

Skip third party unsupported headers. #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Gitonomy/Git/Parser/LogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function doParse()
$this->consumeGPGSignature();

$this->consumeNewLine();
$this->consumeUnsupportedLinesToNewLine();
if ($this->cursor < strlen($this->content)) {
$this->consumeNewLine();
}
Expand All @@ -76,4 +77,15 @@ protected function doParse()
$this->log[] = $commit;
}
}

protected function consumeUnsupportedLinesToNewLine()
{
// Consume any unsupported lines that may appear in the log output. For
// example, gitbutler headers or other custom metadata but this should
// work regardless of the content.
while (!$this->isFinished() && substr($this->content, $this->cursor, 1) !== "\n") {
$this->consumeTo("\n");
$this->consumeNewLine();
}
}
}
42 changes: 42 additions & 0 deletions tests/Gitonomy/Git/Tests/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Gitonomy\Git\Tests;

use Gitonomy\Git\Parser\LogParser;

class LogTest extends AbstractTest
{
/**
Expand Down Expand Up @@ -91,4 +93,44 @@ public function testFirstMessageEmpty()
$commits = $repository->getLog()->getCommits();
$this->assertCount(1, $commits);
}

public function testParsesCommitsWithAndWithoutGitButlerHeaders(): void
{
$logContent = <<<'EOT'
commit 1111111111111111111111111111111111111111
tree abcdefabcdefabcdefabcdefabcdefabcdefabcd
author John Doe <[email protected]> 1620000000 +0000
committer John Doe <[email protected]> 1620000000 +0000

First commit message

commit 2222222222222222222222222222222222222222
tree abcdefabcdefabcdefabcdefabcdefabcdefabcd
parent 1111111111111111111111111111111111111111
author Jane Smith <[email protected]> 1620003600 +0000
committer Jane Smith <[email protected]> 1620003600 +0000
gitbutler-headers-version: 2
gitbutler-change-id: a7bd485c-bae6-45b2-910f-163c78aace81

Commit with GitButler headers

commit 3333333333333333333333333333333333333333
tree abcdefabcdefabcdefabcdefabcdefabcdefabcd
author John Doe <[email protected]> 1620007200 +0000
committer Jane Smith <[email protected]> 1620007200 +0000

Another commit without GitButler headers

EOT;

$parser = new LogParser();
$parser->parse($logContent);

$log = $parser->log;
$this->assertCount(3, $log);

$this->assertEquals("First commit message\n", $log[0]['message']);
$this->assertEquals("Commit with GitButler headers\n", $log[1]['message']);
$this->assertEquals("Another commit without GitButler headers\n", $log[2]['message']);
}
}