matteosister / GitElephant

An abstraction layer for git written in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

clone to existing folder

fuzzy76 opened this issue · comments

I need to clone into a folder I make in advance. However, GitElephant seems to create a subfolder for the repository, no matter what I try.

mkdir($dirname, 0777, TRUE);
$repo = new Repository($dirname);
$repo->cloneFrom($repo, $dirname);
$repo->checkoutAllRemoteBranches();

If $dirname is 'test/one' the repository is checked out as 'test/one/test/one'. If I omit $dirname from cloneFrom(), the repository is check out as 'test/one/repositoryname'.

Be careful with variables names. Seems like you are creating a repo with new Repository and than using that same repo as a source for cloneFrom.

I just tried and this code works as expected:

<?php

require_once __DIR__.'/../vendor/autoload.php';

use GitElephant\Repository;


$gitUrl = 'https://github.com/matteosister/GitElephant.git';
$tempFolder = tempnam(sys_get_temp_dir(), 'ge');
unlink($tempFolder);
mkdir($tempFolder);
echo $tempFolder."\n";
$repo = new Repository($tempFolder);
$repo->cloneFrom($gitUrl, $tempFolder);

it prints out the random temp folder. And if I go there the repository is at the root level, as it's supposed to be.

there is also a shortcut for cloning from a git url to a folder:

$repo = Repository::createFromRemote($gitRepo, $tempFolder);

Let me know if it works.