/** * Validates the branch. * * @param string $branch * @param VersionParser|null $parser * * @return false|string */ public static function validateBranch($branch, VersionParser $parser = null) { if (null === $parser) { $parser = new VersionParser(); } $normalize = $parser->normalizeBranch($branch); if (false !== strpos($normalize, '.9999999-dev')) { return false; } return $normalize; }
private function guessSvnVersion(array $packageConfig, $path) { SvnUtil::cleanEnv(); // try to fetch current version from svn if (0 === $this->process->execute('svn info --xml', $output, $path)) { $trunkPath = isset($packageConfig['trunk-path']) ? preg_quote($packageConfig['trunk-path'], '#') : 'trunk'; $branchesPath = isset($packageConfig['branches-path']) ? preg_quote($packageConfig['branches-path'], '#') : 'branches'; $tagsPath = isset($packageConfig['tags-path']) ? preg_quote($packageConfig['tags-path'], '#') : 'tags'; $urlPattern = '#<url>.*/(' . $trunkPath . '|(' . $branchesPath . '|' . $tagsPath . ')/(.*))</url>#'; if (preg_match($urlPattern, $output, $matches)) { if (isset($matches[2]) && ($branchesPath === $matches[2] || $tagsPath === $matches[2])) { // we are in a branches path $version = $this->versionParser->normalizeBranch($matches[3]); if ('9999999-dev' === $version) { $version = 'dev-' . $matches[3]; } return $version; } return $this->versionParser->normalize(trim($matches[1])); } } }
/** * @dataProvider successfulNormalizedBranches */ public function testNormalizeBranch($input, $expected) { $parser = new VersionParser(); $this->assertSame((string) $expected, (string) $parser->normalizeBranch($input)); }
/** * @return string */ public function getVersionAlias() { $extra = $this->getExtra(); if (isset($extra['branch-alias'][$this->getVersion()])) { $parser = new VersionParser(); $version = $parser->normalizeBranch(str_replace('-dev', '', $extra['branch-alias'][$this->getVersion()])); return preg_replace('{(\\.9{7})+}', '.x', $version); } return ''; }