/** * Instanciate a new file * * @param Repository $repository The Git repository hosting the file. * @param string $file_name Opened file full path name */ public function __construct(Repository $repository, $file_name) { if ('/' != $file_name[0]) { $file_name = $repository->getDir() . '/' . $file_name; } parent::__construct($file_name); $this->repository = $repository; $this->setInfoClass(__CLASS__); }
public function testGetIterator() { $repository = new Repository(__DIR__ . self::REPOSITORY_NAME . "/.git"); $index = $repository->getIndex(); $index->add("example"); $index->write(); $it = $index->getIterator(); $this->assertInstanceOf("Iterator", $it); }
/** * @expectedException Git\Exception\GitRuntimeException */ public function testCreate() { Repository::create('/dev/null'); }
public function testGetEntry() { $repository = new Repository("./.git"); $tree = $repository->getTree("f031269837fabfa2c63e7a37b000a91171855f3f"); $this->assertEquals("tests", $tree->getEntry(9)->name, "can't get specified entry"); }
/** * Execute a git command on the repository being manipulated * * This method will start a new process on the current machine and * run git commands. Once the command has been run, the method will * return the command line output. * * @param Repository $repository Repository where the command will be run * @param string $command Git command to be run * @return string Returns the command output */ public function run(Repository $repository, $command) { $descriptors = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $process = proc_open($this->getPath() . ' ' . $command, $descriptors, $pipes, $repository->getPath()); if (!is_resource($process)) { throw new \RuntimeException('Unable to execute command: ' . $command); } $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); if (!empty($stderr)) { throw new \RuntimeException($stderr); } $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); proc_close($process); return $stdout; }