public function getCurrentBranch() { //quieted: see https://github.com/kzykhys/PHPGit/issues/4 @($branches = $this->git->branch()); foreach ($branches as $branch) { if (isset($branch['current']) && $branch['current'] === true) { return $branch['name']; } } }
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); }
public function testCheckoutCreate() { $git = new Git(); $git->setRepository($this->directory); $git->checkout->create('next'); $branches = $git->branch(); $this->assertArrayHasKey('next', $branches); $this->assertTrue($branches['next']['current']); $git->checkout->create('develop', 'next'); $branches = $git->branch(); $this->assertArrayHasKey('develop', $branches); $this->assertTrue($branches['develop']['current']); }
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); }
/** * Get all versions for the given manual. * * @param string $manual * @return array */ public function getVersions($manual) { $manualDir = $this->storagePath . '/' . $manual; return $this->cache->remember("cache.{$manual}.branches", 10, function () use($manualDir) { $this->git->setRepository($manualDir); $this->git->fetch('origin'); return array_filter(array_map(function ($branch) { return preg_replace('/[\\w]+?\\//', '', $branch['name']); }, $this->git->branch(['remotes' => true])), function ($branch) { return $branch !== 'HEAD'; }); }); }