public function testSetBranchesAdd() { $git = new Git(); $git->clone('https://github.com/kzykhys/Text.git', $this->directory); $git->setRepository($this->directory); $git->remote->branches->add('origin', array('gh-pages')); }
/** * @expectedException \PHPGit\Exception\GitException * @expectedExceptionCode 128 */ public function testException() { $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $git->add('foo'); }
public function testCheckoutOrphan() { $git = new Git(); $git->setRepository($this->directory); $git->checkout->orphan('gh-pages', 'master', array('force' => true)); $status = $git->status(); $this->assertEquals('gh-pages', $status['branch']); }
public function testRemotePrune() { $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->prune('origin'); }
/** * @param Package $package * @return array */ public function transform(Package $package) { list($vendor, $name) = $this->splitVendorAndName($package->getName()); $this->diskFactory->disk('local')->makeDirectory('storage/modules/' . $package->getName()); if ($this->diskFactory->disk('local')->allDirectories('storage/modules/' . $package->getName()) === []) { $this->git->clone($package->getRepository(), storage_path('modules/' . $package->getName())); } return ['vendor' => $vendor, 'name' => $name, 'excerpt' => $package->getDescription(), 'description' => $this->getReadmeFileFor($package), 'favourites' => $package->getFavers(), 'total_downloads' => $package->getDownloads()->getTotal(), 'monthly_downloads' => $package->getDownloads()->getMonthly(), 'daily_downloads' => $package->getDownloads()->getDaily()]; }
public function fire() { $this->comment('Updating documentation...'); $this->git->setRepository(public_path() . '/Documentation'); $this->git->pull('origin', 'master'); $this->generator->generate(); $this->call('cache:clear'); $this->info('Documentation updated!'); }
public function testPull() { $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->pull('origin', 'master'); $this->assertFileExists($this->directory . '/README.md'); }
public function testFetchAll() { $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->fetch->all(); $tags = $git->tag(); $this->assertContains('v1.0.0', $tags); }
public function testSetHeadRemote() { $git = new Git(); $git->clone('https://github.com/kzykhys/Text.git', $this->directory); $git->setRepository($this->directory); $before = $git->branch(array('all' => true)); $git->remote->head->delete('origin'); $git->remote->head->remote('origin'); $after = $git->branch(array('all' => true)); $this->assertEquals($before, $after); }
/** * Generates an example page. */ public function printPage() { $output = t('Hello <strong>@value!</strong>', array('@value' => $this->demoService->getDemoValue())); // $parser = new Jsonp(); // ; // $repo = new Repo('/Users/nikolay/Sites/gittest');. $git = new Git(); $git->setRepository('/Users/nikolay/Sites/gittest'); kint($git->log()); return array('#markup' => $output); }
public function testSetUrlDelete() { $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $git->remote->add('origin', 'http://example.com/test.git'); $git->remote->url->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->url->delete('origin', 'https://github.com'); $remotes = $git->remote(); $this->assertEquals('http://example.com/test.git', $remotes['origin']['fetch']); }
public function testClone() { $git = new Git(); $git->clone('https://github.com/kzykhys/Text.git', $this->directory); $git->setRepository($this->directory); $this->assertFileExists($this->directory . '/.git'); $filesystem = new Filesystem(); $filesystem->remove($this->directory); $git->setRepository('.'); $git->clone('https://github.com/kzykhys/Text.git', $this->directory, array('shared' => true)); $this->assertFileExists($this->directory . '/.git'); }
public function testException() { $git = new Git(); $git->setRepository(sys_get_temp_dir()); try { $git->status(); $this->fail('Previous operation should fail'); } catch (GitException $e) { $command = $e->getCommandLine(); $command = str_replace(array('"', "'"), '', $command); $this->assertStringEndsWith('status --porcelain -s -b --null', $command); } }
public function testBranchDelete() { $git = new Git(); $git->setRepository($this->directory); $git->branch->create('1.0'); $git->branch->create('2.0'); $branches = $git->branch(); $this->assertCount(3, $branches); $git->branch->delete('1.0'); $branches = $git->branch(); $this->assertCount(2, $branches); $git->branch->delete('2.0', array('force' => true)); $branches = $git->branch(); $this->assertCount(1, $branches); }
public function testConfigAdd() { $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $before = $git->config(); $git->config->set('user.name', 'John Doe'); $git->config->add('user.name', 'Foo'); $config = $git->config(); $this->assertArrayHasKey('user.name', $config); $expected = "John Doe\nFoo"; if (isset($before['user.name'])) { $expected = $before['user.name'] . "\n" . $expected; } $this->assertEquals($expected, $config['user.name']); }
public function testPush() { $filesystem = new Filesystem(); $git = new Git(); $git->init($this->directory, array('shared' => true, 'bare' => true)); $git->clone('file://' . realpath($this->directory), $this->directory . '2'); $git->setRepository($this->directory . '2'); $filesystem->dumpFile($this->directory . '2/test.txt', 'foobar'); $git->add('test.txt'); $git->commit('test'); $git->push('origin', 'master'); $git->clone('file://' . realpath($this->directory), $this->directory . '3'); $this->assertFileExists($this->directory . '3/test.txt'); $filesystem->remove($this->directory . '2'); $filesystem->remove($this->directory . '3'); }
public function testCreateTagFromCommit() { $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'); $log = $git->log(null, null, array('limit' => 1)); $git->tag->create('v1.0.0', $log[0]['hash']); $this->assertCount(1, $git->tag()); }
/** * Return the path to the checked out repository for the supplied * manual and version. * * @param string $manual * @param string $version * @return string */ private function getStoragePath($manual, $version) { $storagePath = storage_path('codex/' . $manual . '/' . $version); if (!file_exists($storagePath)) { $this->files->copyDirectory($this->storagePath . '/' . $manual, $storagePath, 0); $this->git->setRepository($storagePath); $this->git->checkout($version); } else { $this->cache->remember("{$manual}.{$version}.checkout", 10, function () use($version, $storagePath) { $this->git->setRepository($storagePath); $this->git->pull('origin', $version); return true; }); } return $storagePath; }
/** * Ensures that all dependencies are present. * * If not injected previously, default instances are created. The commands * need all the depedencies. */ private function ensureDependencies() { $workingDir = getcwd(); if ($this->vcs === null) { $git = new Git(); $git->setRepository($workingDir); $this->vcs = new Git2($git); } if ($this->flow === null) { $this->flow = new GitFlowBranch($this->vcs); } if ($this->composerFile === null) { $file = new \SplFileObject($workingDir . '/composer.json'); $this->composerFile = new ComposerFile($file); } }
public function testShow() { $filesystem = new Filesystem(); $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $filesystem->dumpFile($this->directory . '/README.md', 'foobar'); $git->add('README.md'); $git->commit('Initial commit'); $git->show('master', array('format' => 'oneline')); }
public function testShortlogSummary() { $filesystem = new Filesystem(); $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $git->config->set('user.name', 'Name One'); $git->config->set('user.email', '*****@*****.**'); $filesystem->dumpFile($this->directory . '/test.txt', ''); $git->add('test.txt'); $git->commit('1'); $filesystem->dumpFile($this->directory . '/test2.txt', ''); $git->add('test2.txt'); $git->commit('2'); $git->config->set('user.name', 'Name Two'); $git->config->set('user.email', '*****@*****.**'); $filesystem->dumpFile($this->directory . '/test3.txt', ''); $git->add('test3.txt'); $git->commit('3'); $summary = $git->shortlog->summary(); $this->assertEquals(array('Name One <*****@*****.**>' => 2, 'Name Two <*****@*****.**>' => 1), $summary); }
public function testRmCached() { $filesystem = new Filesystem(); $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $filesystem->dumpFile($this->directory . '/README.md', 'foo'); $git->add('README.md'); $git->commit('Initial commit'); $git->rm->cached('README.md'); $git->commit('Delete README.md'); $this->assertFileExists($this->directory . '/README.md'); $tree = $git->tree(); $this->assertEquals(array(), $tree); }
public function testCommit() { $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $filesystem = new Filesystem(); $filesystem->dumpFile($this->directory . '/test.txt', ''); $git->add('test.txt'); $git->commit('Initial commit'); $logs = $git->log('test.txt'); $this->assertCount(1, $logs); }
public function testTrackingBranchStatus() { $filesystem = new Filesystem(); $git = new Git(); $git->clone('https://github.com/kzykhys/Text.git', $this->directory); $git->setRepository($this->directory); $filesystem->dumpFile($this->directory . '/test.txt', '1'); $git->add('test.txt'); $git->commit('test'); $status = $git->status(); $this->assertEquals('master', $status['branch']); }
public function testMv() { $filesystem = new Filesystem(); $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $filesystem->dumpFile($this->directory . '/test.txt', 'foo'); $git->add('test.txt'); $git->commit('Initial commit'); $git->mv('test.txt', 'test2.txt'); $this->assertFileExists($this->directory . '/test2.txt'); }
public function testCatSize() { $filesystem = new Filesystem(); $filesystem->mkdir($this->directory); $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $filesystem->dumpFile($this->directory . '/test.txt', 'foo'); $git->add('test.txt'); $git->commit('Initial commit'); $tree = $git->tree(); $this->assertEquals(3, $git->cat->size($tree[0]['hash'])); }
public function testArchive() { $filesystem = new Filesystem(); $filesystem->mkdir($this->directory); $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $filesystem->dumpFile($this->directory . '/test.txt', 'hello'); $git->add('test.txt'); $git->commit('Initial commit'); $git->archive($this->directory . '/test.zip', 'master', null, array('format' => 'zip', 'prefix' => 'test/')); $this->assertFileExists($this->directory . '/test.zip'); }
public function testDescribeTags() { $filesystem = new Filesystem(); $git = new Git(); $git->init($this->directory); $git->setRepository($this->directory); $filesystem->dumpFile($this->directory . '/README.md', 'hello'); $git->add('README.md'); $git->commit('Initial commit'); $git->tag->create('v1.0.0'); $version = $git->describe->tags('HEAD'); $this->assertEquals('v1.0.0', $version); $filesystem->dumpFile($this->directory . '/README.md', 'hello2'); $git->add('README.md'); $git->commit('Fixes README'); $version = $git->describe->tags('HEAD'); $this->assertStringStartsWith('v1.0.0', $version); $this->assertStringEndsNotWith('v1.0.0', $version); }
/** * 1. Checkout to new branch modvert/test based on origin/test * or movert/develop based on origin/develop * 2. Load remote resources * 3. Show message: * 1. Check changes `git diff --name-only -- storage` * 2. Commit if has changes * 3. Checkout to the main branch (test/develop/feature/QUES-*) * 4. Merge `git merge movert/test` or `git merge movert/develop` * * Если */ public function loadRemote($stage) { /** @var $resource IResource **/ $repository = new Repository(); $driver = new RemoteDriver($stage); $repository->setDriver($driver); if ($repository->isLocked()) { // If remote stage is Locked return $this->output->writeln('<error>Remote stage is locked. Please try again!</error>'); } $storage = new Storage($this->getConnection()); $git = new Git(); $git->setRepository(Application::getInstance()->getAppPath()); $status = $git->status(); $current_branch = $status['branch']; // do not checkout if has unstaged changes if (count($status['changes'])) { return $this->output->writeln('<error>Please commit changes before!</error>'); } $temp_branch = 'modvert/develop'; $parent_branch = 'origin/develop'; try { $git->branch->delete($temp_branch, ['force' => true]); } catch (\Exception $ex) { /** the branch not found */ } $git->checkout->create($temp_branch, $parent_branch); $storage->loadRemote($stage); $storage_changes = ArrayHelper::matchValue($git->status()['changes'], 'file', '/^storage/'); if (count($storage_changes)) { $this->output->writeln('<info>You have unstaged remote changes! Commit them and merge with main branch!</info>'); } else { $git->checkout($current_branch); } }
/** * @param $package * * @throws \RuntimeException * @throws \Markbench\Exception\TooMuchPackageFoundException * @return string */ protected function getVersion($package) { $json_path = ''; $json_paths = [getcwd() . '/composer.json', __DIR__ . '/../../../../composer.json', __DIR__ . '/../../../../../../composer.json']; foreach ($json_paths as $path) { if (file_exists($path)) { $json_path = $path; break; } } if (!$json_path) { throw new \RuntimeException('Unable to find composer.json'); } $composer = Factory::create(new NullIO(), $json_path); $repository = $composer->getRepositoryManager()->getLocalRepository(); /* @var \Composer\Package\Package[] $packages */ $packages = $repository->findPackages($package); if (($count = count($packages)) > 1) { throw new TooMuchPackageFoundException(); } elseif ($count == 0) { $git = new Git(); $git->setRepository(dirname($json_path)); return $git->describe->tags(); } else { return $packages[0]->getPrettyVersion(); } }