public function testCreateClone() { $dirname = $this->generateTmpDir(); $instance = new VersionControl_Git($dirname); $instance->createClone('git://gist.github.com/265855.git'); $this->assertTrue(is_dir($dirname . DIRECTORY_SEPARATOR . '265855')); $this->removeDirectory($dirname); $dirname = $this->generateTmpDir(); $instance = new VersionControl_Git($dirname); $instance->createClone('git://gist.github.com/265855.git', true); if (version_compare('1.6.0-rc1', $instance->getGitVersion(), '>=')) { // see: http://git.kernel.org/?p=git/git.git;a=commit;h=6612f87 $this->assertTrue(is_file($dirname . DIRECTORY_SEPARATOR . '265855' . DIRECTORY_SEPARATOR . 'HEAD')); } else { $this->assertTrue(is_file($dirname . DIRECTORY_SEPARATOR . '265855.git' . DIRECTORY_SEPARATOR . 'HEAD')); } $this->removeDirectory($dirname); $dirname = $this->generateTmpDir(); $instance = new VersionControl_Git($dirname); $instance->createClone('git://gist.github.com/265855.git', true, $dirname . DIRECTORY_SEPARATOR . 'MY_WORKING_COPY'); $this->assertTrue(is_dir($dirname . DIRECTORY_SEPARATOR . 'MY_WORKING_COPY')); $this->assertTrue(realpath($instance->getDirectory()) === realpath($dirname . DIRECTORY_SEPARATOR . 'MY_WORKING_COPY')); $this->removeDirectory($dirname); $dirname = $this->generateTmpDir(); $instance = new VersionControl_Git($dirname); $instance->createClone('git://gist.github.com/265855.git', false, $dirname); $this->assertTrue(is_file($dirname . DIRECTORY_SEPARATOR . 'patch_for_pecl_runkit.diff')); $this->removeDirectory($dirname); }
/** * Create a shallow clone with a history truncated to the specified number of revisions. * * @param VersionControl_Git $client * * @throws VersionControl_Git_Exception */ protected function doShallowClone(VersionControl_Git $client) { $command = $client->getCommand('clone')->setOption('depth', $this->getDepth())->setOption('q')->addArgument($this->getRepository())->addArgument($this->getTargetPath()); if (is_dir($this->getTargetPath()) && version_compare('1.6.1.4', $client->getGitVersion(), '>=')) { $isEmptyDir = true; $entries = scandir($this->getTargetPath()); foreach ($entries as $entry) { if ('.' !== $entry && '..' !== $entry) { $isEmptyDir = false; break; } } if ($isEmptyDir) { @rmdir($this->getTargetPath()); } } $command->execute(); }