Skip to content

Commit aad3a12

Browse files
committed
Use "git show" to get pubspec for a particular version
1 parent bb0fb5a commit aad3a12

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/src/source/git.dart

+20-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ class GitSource extends CachedSource {
6767
}
6868
try {
6969
// Use Version.parse to determine valid version tags
70-
PackageId packageAtVersion = new PackageId(
71-
name, this.name, new Version.parse(version), description);
70+
Version validVersion = new Version.parse(version);
7271
// Fetch the pubspec for this version
73-
validVersions.add(await describeUncached(packageAtVersion));
72+
Pubspec pubspec = await _getPubspec(cachePath, validVersion.toString());
73+
if (pubspec != null) {
74+
validVersions.add(pubspec);
75+
}
7476
} on FormatException {}
7577
}
7678

@@ -352,6 +354,21 @@ class GitSource extends CachedSource {
352354
});
353355
}
354356

357+
/// Use `git show` to get the pubspec.yaml at a particular ref,
358+
/// then parse it into a Pubspec object
359+
///
360+
/// It is possible that a pubspec didn't always exist, return null if
361+
/// that is the case.
362+
Future<Pubspec> _getPubspec(String repoPath, String ref) {
363+
return git.run(['show', '$ref:pubspec.yaml'], workingDir: repoPath)
364+
.catchError((_) => null)
365+
.then((result) {
366+
if (result != null) {
367+
return new Pubspec.parse(result.join('\n'), systemCache.sources);
368+
}
369+
});
370+
}
371+
355372
/// Returns the path to the canonical clone of the repository referred to by
356373
/// [id] (the one in `<system cache>/git/cache`).
357374
String _repoCachePath(PackageId id) {

0 commit comments

Comments
 (0)