/** * test repository getter and setter * * @covers GitElephant\Objects\Object::getRepository * @covers GitElephant\Objects\Object::setRepository */ public function testGetSetRepository() { $this->initRepository('object1', 1); $repo1 = $this->getRepository(1); $this->initRepository('object2', 2); $repo2 = $this->getRepository(2); $object = new Object($repo1, 'permissions', 'type', 'sha', 'size', 'name', 'path'); // dummy params $this->assertSame($repo1, $object->getRepository()); $object->setRepository($repo2); $this->assertSame($repo2, $object->getRepository()); }
/** * Build an object log command * * @param \GitElephant\Objects\Object $obj the Object to get the log for * @param \GitElephant\Objects\Branch|string|null $branch the branch to consider * @param int|null $limit limit to n entries * @param int|null $offset skip n entries * * @throws \RuntimeException * @return string */ public function showObjectLog(Object $obj, $branch = null, $limit = null, $offset = null) { $subject = null; if (null !== $branch) { if ($branch instanceof Branch) { $subject .= $branch->getName(); } else { $subject .= (string) $branch; } } return $this->showLog($subject, $obj->getFullPath(), $limit, $offset); }
/** * command to show content of a Object at a given Treeish point * * @param \GitElephant\Objects\Object $object a Object instance * @param \GitElephant\Objects\TreeishInterface|string $treeish an object with TreeishInterface interface * * @throws \RuntimeException * @return string */ public function content(Object $object, $treeish) { $this->clearAll(); if ($treeish instanceof TreeishInterface) { $sha = $treeish->getSha(); } else { $sha = $treeish; } $this->addCommandName(static::GIT_CAT_FILE); // pretty format $this->addCommandArgument('-p'); $this->addCommandSubject($sha . ':' . $object->getFullPath()); return $this->getCommand(); }
/** * Parse a single line into pieces * * @param string $line a single line output from the git binary * * @return mixed */ private function parseLine($line) { if ($line == '') { return; } $slices = Object::getLineSlices($line); if ($this->isBlob()) { $this->pathChildren[] = $this->blob->getName(); } else { if ($this->isRoot()) { // if is root check for first children $pattern = '/(\\w+)\\/(.*)/'; $replacement = '$1'; } else { // filter by the children of the path $actualPath = $this->subject->getFullPath(); if (!preg_match(sprintf('/^%s\\/(\\w*)/', preg_quote($actualPath, '/')), $slices['fullPath'])) { return; } $pattern = sprintf('/^%s\\/(\\w*)/', preg_quote($actualPath, '/')); $replacement = '$1'; } $name = preg_replace($pattern, $replacement, $slices['fullPath']); if (strpos($name, '/') !== false) { return; } if (!in_array($name, $this->pathChildren)) { $path = rtrim(rtrim($slices['fullPath'], $name), '/'); $treeObject = new TreeObject($this->repository, $slices['permissions'], $slices['type'], $slices['sha'], $slices['size'], $name, $path); $this->children[] = $treeObject; $this->pathChildren[] = $name; } } }
/** * @param string|Object $source source name * @param string $target dest name * * @throws \RuntimeException * @throws \InvalidArgumentException * @return string */ public function rename($source, $target) { if ($source instanceof Object) { if (!$source->isBlob()) { throw new \InvalidArgumentException("The given object is not a blob, it couldn't be renamed"); } $sourceName = $source->getFullPath(); } else { $sourceName = $source; } $this->clearAll(); $this->addCommandName(self::MV_COMMAND); // Skip move or rename actions which would lead to an error condition $this->addCommandArgument('-k'); $this->addCommandSubject($sourceName); $this->addCommandSubject2($target); return $this->getCommand(); }
/** * tree of a given path * * @param string $ref reference * @param string|Object $path path * * @throws \RuntimeException * @return string */ public function tree($ref = 'HEAD', $path = null) { if ($path instanceof Object) { $subjectPath = $path->getFullPath() . ($path->isTree() ? '/' : ''); } else { $subjectPath = $path; } $what = $ref; if ($ref instanceof TreeishInterface) { $what = $ref->getSha(); } $this->clearAll(); $this->addCommandName(self::LS_TREE_COMMAND); $this->addCommandArgument('-l'); $subject = $what; $this->addCommandSubject($subject); $this->addPath($subjectPath); return $this->getCommand(); }