Skip to content
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
28 changes: 15 additions & 13 deletions src/Gitonomy/Git/Parser/DiffParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,22 @@ protected function doParse(): void
$newMode = $oldMode = $vars[0];
}
$this->consumeNewLine();
}

// verifying if the file was deleted or created
if ($this->expects('--- ')) {
$oldName = '/dev/null' === $this->consumeTo("\n") ? '/dev/null' : $oldName;
$this->consumeNewLine();
$this->consume('+++ ');
$newName = '/dev/null' === $this->consumeTo("\n") ? '/dev/null' : $newName;
$this->consumeNewLine();
} elseif ($this->expects('Binary files ')) {
$vars = $this->consumeRegexp('/"?(.*?)"? and "?(.*?)"? differ\n/');
$isBinary = true;
$oldName = $vars[1];
$newName = $vars[2];
}
// verifying if the file was deleted or created
// Note: a dirty submodule diff has no "index " line, so this must
// not be nested inside the block above.
if ($this->expects('--- ')) {
$oldName = '/dev/null' === $this->consumeTo("\n") ? '/dev/null' : $oldName;
$this->consumeNewLine();
$this->consume('+++ ');
$newName = '/dev/null' === $this->consumeTo("\n") ? '/dev/null' : $newName;
$this->consumeNewLine();
} elseif ($this->expects('Binary files ')) {
$vars = $this->consumeRegexp('/"?(.*?)"? and "?(.*?)"? differ\n/');
$isBinary = true;
$oldName = $vars[1];
$newName = $vars[2];
}

$oldName = '/dev/null' === $oldName ? null : substr($oldName, 2);
Expand Down
21 changes: 21 additions & 0 deletions tests/Gitonomy/Git/Tests/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ public function testEmptyOldFile(): void
$this->assertSame('test', $firstFile->getOldName());
}

public function testDirtySubmoduleWithoutRaw(): void
{
$this->expectUserDeprecationMessage('Using Diff::parse without raw information is deprecated. See https://github.com/gitonomy/gitlib/issues/227.');

$diff = Diff::parse(<<<'DIFF'
diff --git a/sub b/sub
--- a/sub
+++ b/sub
@@ -1 +1 @@
-Subproject commit e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+Subproject commit e69de29bb2d1d6434b8b29ae775ad8c2e48c5391-dirty

DIFF);
$firstFile = $diff->getFiles()[0];

$this->assertFalse($firstFile->isCreation());
$this->assertFalse($firstFile->isDeletion());
$this->assertSame('sub', $firstFile->getOldName());
$this->assertSame('sub', $firstFile->getNewName());
}

protected function verifyCreateCommitDiff(Diff $diff): void
{
$files = $diff->getFiles();
Expand Down