Skip to content

Commit

Permalink
Use uris for paths in git source descriptions (#3063)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm authored Aug 10, 2021
1 parent 97a0033 commit 9f2ddc0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/src/source/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class GitSource extends Source {
return {'relative': relative, 'url': url};
}

/// Returns [path] normalized.
///
/// Throws a [FormatException] if [path] isn't a relative url or null.
String _validatedPath(dynamic path) {
path ??= '.';
Expand All @@ -161,7 +163,7 @@ class GitSource extends Source {
"The 'path' field of the description must not reach outside the "
'repository.');
}
return p.normalize(parsed.toString());
return p.url.normalize(parsed.toString());
}

/// If [description] has a resolved ref, print it out in short-form.
Expand Down Expand Up @@ -352,7 +354,7 @@ class BoundGitSource extends CachedSource {

return Package.load(
id.name,
p.join(revisionCachePath, id.description['path']),
p.join(revisionCachePath, p.fromUri(id.description['path'])),
systemCache.sources);
});
}
Expand Down
60 changes: 56 additions & 4 deletions test/get/git/path_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import 'package:path/path.dart' as p;
import 'package:pub/src/io.dart';
import 'package:pub/src/lock_file.dart';
import 'package:pub/src/source_registry.dart';
import 'package:test/test.dart';

import '../../descriptor.dart' as d;
Expand Down Expand Up @@ -47,14 +49,14 @@ void main() {

var repo = d.git('foo.git', [
d.dir('sub', [
d.dir('dir', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')])
d.dir('dir%', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')])
])
]);
await repo.create();

await d.appDir({
'sub': {
'git': {'url': '../foo.git', 'path': 'sub/dir'}
'git': {'url': '../foo.git', 'path': 'sub/dir%25'}
}
}).create();

Expand All @@ -65,15 +67,65 @@ void main() {
d.dir('cache', [d.gitPackageRepoCacheDir('foo')]),
d.hashDir('foo', [
d.dir('sub', [
d.dir('dir', [d.libDir('sub', '1.0.0')])
d.dir('dir%', [d.libDir('sub', '1.0.0')])
])
])
])
]).validate();

await d.appPackagesFile({
'sub': pathInCache('git/foo-${await repo.revParse('HEAD')}/sub/dir')
'sub': pathInCache('git/foo-${await repo.revParse('HEAD')}/sub/dir%25')
}).validate();

final lockFile = LockFile.load(
p.join(d.sandbox, appPath, 'pubspec.lock'), SourceRegistry());

expect(lockFile.packages['sub'].description['path'], 'sub/dir%25',
reason: 'use uris to specify the path relative to the repo');
});

test('depends on a package in a deep subdirectory, non-relative uri',
() async {
ensureGit();

var repo = d.git('foo.git', [
d.dir('sub', [
d.dir('dir%', [d.libPubspec('sub', '1.0.0'), d.libDir('sub', '1.0.0')])
])
]);
await repo.create();

await d.appDir({
'sub': {
'git': {
'url': p.toUri(p.join(d.sandbox, 'foo.git')).toString(),
'path': 'sub/dir%25'
}
}
}).create();

await pubGet();

await d.dir(cachePath, [
d.dir('git', [
d.dir('cache', [d.gitPackageRepoCacheDir('foo')]),
d.hashDir('foo', [
d.dir('sub', [
d.dir('dir%', [d.libDir('sub', '1.0.0')])
])
])
])
]).validate();

await d.appPackagesFile({
'sub': pathInCache('git/foo-${await repo.revParse('HEAD')}/sub/dir%25')
}).validate();

final lockFile = LockFile.load(
p.join(d.sandbox, appPath, 'pubspec.lock'), SourceRegistry());

expect(lockFile.packages['sub'].description['path'], 'sub/dir%25',
reason: 'use uris to specify the path relative to the repo');
});

test('depends on multiple packages in subdirectories', () async {
Expand Down

0 comments on commit 9f2ddc0

Please sign in to comment.