/** * Parse the diff command output to FileInfo objects * * @param string $output * @param array $arguments * @throws \Exception * @return string|\Webcreate\Vcs\Common\VcsFileInfo[] */ public function parseDiffOutput($output, array $arguments = array()) { if (!isset($arguments['--name-status']) || false === $arguments['--name-status']) { // non name-status results are not supported return $output; } $lines = explode("\n", rtrim($output)); $retval = array(); foreach ($lines as $line) { if (preg_match('/([ACDMRTUXB])\\s+(.*)?/', $line, $matches)) { list($fullmatch, $x, $file) = $matches; $file = new VcsFileInfo($file, $this->getClient()->getHead()); $file->setStatus($x); $retval[] = $file; } else { throw new \Exception('Unable to parse line "' . $line . '"'); } } return $retval; }
/** * @dataProvider existingPathProvider */ public function testDiff($filename) { // first we need a checkout $result = $this->client->checkout($this->checkoutDir); // next modify a file $tmpfile = $this->checkoutDir . '/' . $filename; file_put_contents($tmpfile, uniqid(null, true)); // added to the staged file list $this->client->add($filename); // now let's commit it $this->client->commit("changed file contents"); // get the log $log = $this->client->log($filename); $firstLog = end($log); $firstRevision = $firstLog->getRevision(); $diff = $this->client->diff($filename, $filename, $firstRevision); $file = new VcsFileInfo($filename, $this->client->getHead()); $file->setStatus(Status::MODIFIED); $expected = array($file); $this->assertContainsOnlyInstancesOf('Webcreate\\Vcs\\Common\\VcsFileInfo', $diff); $this->assertEquals($expected, $diff); }
/** * Parse the Xml result from Subversion * * @param string $output * @param array $arguments * @return array */ protected function parseDiffOutput($output, array $arguments = array()) { if (!isset($arguments['--xml']) || false === $arguments['--xml']) { // non xml results are not supported return $output; } if (!isset($arguments['--summarize']) || false === $arguments['--summarize']) { // non summarized results are not supported return $output; } $sxml = simplexml_load_string($output); $retval = array(); foreach ($sxml->xpath('//path') as $item) { $url = (string) $item; $path = ltrim(str_replace($this->client->getSvnUrl(''), '', $url), '/'); // @todo move to a Mapper class? $status = (string) $item->attributes()->item; switch ($status) { case "modified": $status = Status::MODIFIED; break; case "added": $status = Status::ADDED; break; case "deleted": $status = Status::DELETED; break; } $file = new VcsFileInfo($path, $this->getClient()->getHead()); $file->setStatus($status); $retval[] = $file; } return $retval; }