Skip to content

Commit 1e12f5d

Browse files
committed
svn - changing default --from value + fix 'Unable to find the wrapper "svn"'
1 parent 0bcf3f7 commit 1e12f5d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

composer-lock-diff

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function load($fileish, $base_path = '', $vcs) {
163163
$fileish = $base_path . 'composer.lock';
164164
}
165165

166-
if (isUrl($fileish)) {
166+
if (strpos('svn://', $fileish) !== 0 && isUrl($fileish)) {
167167
if (! in_array(parse_url($fileish, PHP_URL_SCHEME), stream_get_wrappers())) {
168168
error_log("Error: no stream wrapper to open '$fileish'");
169169
exit(1);
@@ -172,12 +172,12 @@ function load($fileish, $base_path = '', $vcs) {
172172
return mustDecodeJson(file_get_contents($fileish), $fileish);
173173
}
174174

175-
if (file_exists($fileish)) {
175+
if (strpos('svn://', $fileish) !== 0 && file_exists($fileish)) {
176176
return mustDecodeJson(file_get_contents($fileish), $fileish);
177177
}
178178

179179
//try to find vcs revision
180-
if (strtolower($vcs) == 'git'){
180+
if ($vcs == 'git'){
181181
if (strpos($orig, ':') === false) {
182182
$fileish .= ':' . $base_path . 'composer.lock';
183183
}
@@ -193,8 +193,12 @@ function load($fileish, $base_path = '', $vcs) {
193193
return mustDecodeJson(implode("\n", $lines), $fileish);
194194
}
195195

196-
elseif (strtolower($vcs) == 'svn'){
197-
if (strpos($orig, '@') === false) {
196+
elseif ($vcs == 'svn'){
197+
# explaination:
198+
# http:// https:// svn:// => absolute url of repository (http/https already handled before)
199+
# ^ => relative url from current workspace repository
200+
# @ => repository url with version
201+
if (preg_match('#^\^|^svn://|@#', $orig) === 0) {
198202
$fileish = $base_path . 'composer.lock@'.$fileish;
199203
}
200204
exec('svn cat '. escapeshellarg($fileish), $lines, $exit);
@@ -311,18 +315,20 @@ function parseOpts() {
311315
}
312316

313317
$path = array_key_exists('path', $given) ? $given['path'] : '';
318+
$vcs = array_key_exists('vcs', $given) ? strtolower($given['vcs']) : vcsDetect($path);
319+
$defaultFrom = $vcs == 'svn' ? "BASE" : "HEAD";
314320

315321
return array(
316322
'path' => $path,
317-
'from' => array_key_exists('from', $given) ? $given['from'] : 'HEAD',
323+
'from' => array_key_exists('from', $given) ? $given['from'] : $defaultFrom,
318324
'to' => array_key_exists('to', $given) ? $given['to'] : '',
319325
'md' => array_key_exists('md', $given),
320326
'json' => array_key_exists('json', $given),
321327
'pretty' => version_compare(PHP_VERSION, '5.4.0', '>=') && array_key_exists('pretty', $given),
322328
'no-links' => array_key_exists('no-links', $given),
323329
'only-prod' => array_key_exists('only-prod', $given),
324330
'only-dev' => array_key_exists('only-dev', $given),
325-
'vcs' => array_key_exists('vcs', $given) ? $given['vcs'] : vcsDetect($path),
331+
'vcs' => $vcs,
326332
);
327333
}
328334

@@ -354,7 +360,8 @@ Options:
354360
-h --help Print this message
355361
--path, -p Base to with which to prefix paths. Default "./"
356362
E.g. `-p app` would look for HEAD:app/composer.lock and app/composer.lock
357-
--from The file, git ref, or git ref with filename to compare from (HEAD:composer.lock)
363+
--from The file, git ref, or git ref with filename to compare from
364+
(git : HEAD:composer.lock, svn: composer.lock@BASE)
358365
--to The file, git ref, or git ref with filename to compare to (composer.lock)
359366
--json Format output as JSON
360367
--pretty Pretty print JSON output (PHP >= 5.4.0)
@@ -368,4 +375,5 @@ EOF;
368375

369376
exit(0);
370377
}
378+
# vim: ff=unix ts=4 ss=4 sr et
371379

0 commit comments

Comments
 (0)