Skip to content

Commit

Permalink
Merge branch 'main' into fix-empty-index
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Beuks authored Jan 29, 2025
2 parents e7a6ac1 + 16214e3 commit a640c6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Gitonomy/Git/Parser/DiffParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected function doParse()
$newMode = $this->consumeTo("\n");
$this->consumeNewLine();
$oldMode = null;
$oldName = '/dev/null';
}
if ($this->expects('old mode ')) {
$oldMode = $this->consumeTo("\n");
Expand All @@ -66,6 +67,7 @@ protected function doParse()
if ($this->expects('deleted file mode ')) {
$oldMode = $this->consumeTo("\n");
$newMode = null;
$newName = '/dev/null';
$this->consumeNewLine();
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Gitonomy/Git/Tests/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,26 @@ public function testThrowErrorOnBlobGetWithoutIndex()
$this->assertSame('', $file->getOldIndex());
$this->assertSame('', $file->getNewIndex());
}

public function testEmptyNewFile()
{
$diff = Diff::parse("diff --git a/test b/test\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n");
$firstFile = $diff->getFiles()[0];

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

public function testEmptyOldFile()
{
$diff = Diff::parse("diff --git a/test b/test\ndeleted file mode 100644\nindex e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000\n");
$firstFile = $diff->getFiles()[0];

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

0 comments on commit a640c6e

Please sign in to comment.