Thanks to visit codestin.com
Credit goes to github.com

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
7 changes: 6 additions & 1 deletion src/Command/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __invoke(string $branch = 'master', string $path = ''): array
{
$objects = [];
$builder = $this->getCommandBuilder();
$builder->add('ls-tree')->add($branch . ':' . $path);
$builder->add($branch . ':' . $path);

$output = $this->run($builder);

Expand All @@ -73,4 +73,9 @@ public function __invoke(string $branch = 'master', string $path = ''): array

return $objects;
}

public function getCommandName(): string
{
return 'ls-tree';
}
}
54 changes: 54 additions & 0 deletions test/Command/TreeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php declare(strict_types=1);
/**
* phpGit - A Git wrapper for PHP
*
* @author https://github.com/inhere
* @link https://github.com/phppkg/phpgit
* @license MIT
*/

namespace PhpGitTest\Command;

use PhpGit\Exception\GitException;
use PhpGit\Git;
use PhpGitTest\BasePhpGitTestCase;
use Symfony\Component\Filesystem\Filesystem;


class TreeTest extends BasePhpGitTestCase
{
public function testListBranch(): void
{
$filesystem = new Filesystem();

$git = new Git();
$git->init($this->directory);
$git->setRepository($this->directory);
$filesystem->dumpFile($this->directory . '/README.md', 'hello');
$git->add('.');
$git->commit('Initial commit');

$result = $git->tree('master');

$this->assertIsArray($result);
$this->assertCount(1, $result);

$inner = array_shift($result);

$this->assertIsArray($inner);
$this->assertArrayHasKey('sort', $inner);
$this->assertEquals('2:README.md', $inner['sort']);

$this->assertArrayHasKey('type', $inner);
$this->assertEquals('blob', $inner['type']);

$this->assertArrayHasKey('mode', $inner);
$this->assertEquals(100644, $inner['mode']);

$this->assertArrayHasKey('hash', $inner);
$this->assertEquals('b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0', $inner['hash']);

$this->assertArrayHasKey('file', $inner);
$this->assertEquals('README.md', $inner['file']);
}
}