Skip to content

Commit

Permalink
add clone branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtARTs36 committed Aug 19, 2020
1 parent b765c99 commit 200bd4a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,26 @@ public function add(string $file): bool
/**
* equals: git clone <url> <folder>
* @param string $url
* @param string|null $branch
* @return bool
*/
public function clone(string $url): bool
public function clone(string $url, string $branch = null): bool
{
$sh = $this->executeCommand($this->newCommand(FileSystem::belowPath($this->dir))
$command = $this->newCommand(FileSystem::belowPath($this->dir))
->addParameter('clone')
->when(!empty($branch), function (ShellCommand $command) use ($branch) {
$command
->addCutOption('b')
->addParameter($branch);
})
->addParameter($url)
->addParameter($folder = FileSystem::endFolder($this->dir)));
->addParameter($folder = FileSystem::endFolder($this->dir));

//

$sh = $this->executeCommand($command);

//

if (Str::contains($sh, "Cloning into '{$folder}'")) {
return true;
Expand Down
15 changes: 15 additions & 0 deletions tests/GitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ public function testClone(): void
"and is not an empty directory.", $dir)->clone($url);
}

/**
* @covers \ArtARTs36\GitHandler\Git::clone
*/
public function testCloneBranch(): void
{
$folder = 'project';
$dir = '/var/web/'. $folder;
$url = 'http://url.git';
$branch = 'dev';

$git = $this->mock("Cloning into '{$folder}' ...", $dir);

self::assertTrue($git->clone($url, $branch));
}

/**
* @covers \ArtARTs36\GitHandler\Git::stash
*/
Expand Down

0 comments on commit 200bd4a

Please sign in to comment.