Skip to content

Commit 619db73

Browse files
authored
Introduce getPackageNameFromGitRepo in package API (#4630)
1 parent c3e5091 commit 619db73

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/pub.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'src/entrypoint.dart';
88
import 'src/exceptions.dart';
99
import 'src/http.dart';
1010
import 'src/pub_embeddable_command.dart';
11+
import 'src/source/git.dart';
1112
import 'src/system_cache.dart';
1213

1314
export 'src/executable.dart'
@@ -67,3 +68,39 @@ class ResolutionFailedException implements Exception {
6768
String message;
6869
ResolutionFailedException._(this.message);
6970
}
71+
72+
/// Given a Git repo that contains a pub package, gets the name of the pub
73+
/// package.
74+
///
75+
/// Will download the repo to the system cache under the assumption that the
76+
/// package will be downloaded afterwards.
77+
///
78+
/// [url] points to the git repository. If it is a relative url, it is resolved
79+
/// as a file url relative to the path [relativeTo].
80+
///
81+
/// [ref] is the commit, tag, or branch name where the package should be looked
82+
/// up when fetching the name. If omitted, 'HEAD' is used.
83+
///
84+
/// [tagPattern] is a string containing `'{{version}}'` as a substring, the
85+
/// latest tag matching the pattern will be used for fetching the name.
86+
///
87+
/// Only one of [ref] and [tagPattern] can be used.
88+
///
89+
/// If [isOffline], only the already cached versions of the repo is used.
90+
Future<String> getPackageNameFromGitRepo(
91+
String url, {
92+
String? ref,
93+
String? path,
94+
String? tagPattern,
95+
String? relativeTo,
96+
bool isOffline = false,
97+
}) async {
98+
return await GitSource.instance.getPackageNameFromRepo(
99+
url,
100+
ref,
101+
path,
102+
SystemCache(isOffline: isOffline),
103+
relativeTo: relativeTo,
104+
tagPattern: tagPattern,
105+
);
106+
}

lib/src/source/git.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class GitSource extends CachedSource {
290290
String? ref,
291291
String? path,
292292
SystemCache cache, {
293-
required String relativeTo,
293+
required String? relativeTo,
294294
required String? tagPattern,
295295
}) async {
296296
assert(

0 commit comments

Comments
 (0)