Skip to content

Commit 59406fa

Browse files
authored
Add 'tag_pattern' feature to git dependencies (#4427)
1 parent 141f46e commit 59406fa

12 files changed

+660
-18
lines changed

lib/src/command/add.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ For example (follow the same format including spaces):
117117
help: 'Path of git package in repository',
118118
hide: true,
119119
);
120+
argParser.addOption(
121+
'git-tag-pattern',
122+
help: 'The tag-pattern to search for versions in repository',
123+
hide: true,
124+
);
120125
argParser.addOption(
121126
'hosted-url',
122127
help: 'URL of package host server',
@@ -543,6 +548,11 @@ Specify multiple sdk packages with descriptors.''');
543548
if (gitUrl == null) {
544549
usageException('The `--git-url` is required for git dependencies.');
545550
}
551+
if (argResults.gitRef != null && argResults.tagPattern != null) {
552+
usageException(
553+
'Cannot provide both `--git-ref` and `--git-tag-pattern`.',
554+
);
555+
}
546556

547557
/// Process the git options to return the simplest representation to be
548558
/// added to the pubspec.
@@ -554,6 +564,7 @@ Specify multiple sdk packages with descriptors.''');
554564
containingDir: p.current,
555565
ref: argResults.gitRef,
556566
path: argResults.gitPath,
567+
tagPattern: argResults.tagPattern,
557568
),
558569
);
559570
} on FormatException catch (e) {
@@ -789,6 +800,8 @@ extension on ArgResults {
789800
bool get isDryRun => flag('dry-run');
790801
String? get gitUrl => this['git-url'] as String?;
791802
String? get gitPath => this['git-path'] as String?;
803+
String? get tagPattern => this['git-tag-pattern'] as String?;
804+
792805
String? get gitRef => this['git-ref'] as String?;
793806
String? get hostedUrl => this['hosted-url'] as String?;
794807
String? get path => this['path'] as String?;

lib/src/command/dependency_services.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class DependencyServicesApplyCommand extends PubCommand {
424424
} else if (targetRevision != null &&
425425
(lockFileYaml['packages'] as Map).containsKey(targetPackage)) {
426426
final ref = entrypoint.lockFile.packages[targetPackage]!.toRef();
427+
427428
final currentDescription = ref.description as GitDescription;
428429
final updatedRef = PackageRef(
429430
targetPackage,
@@ -432,6 +433,7 @@ class DependencyServicesApplyCommand extends PubCommand {
432433
path: currentDescription.path,
433434
ref: targetRevision,
434435
containingDir: directory,
436+
tagPattern: currentDescription.tagPattern,
435437
),
436438
);
437439
final versions = await cache.getVersions(updatedRef);

lib/src/global_packages.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ class GlobalPackages {
9393
required bool overwriteBinStubs,
9494
String? path,
9595
String? ref,
96+
String? tagPattern,
9697
}) async {
9798
final name = await cache.git.getPackageNameFromRepo(
9899
repo,
99100
ref,
100101
path,
101102
cache,
102103
relativeTo: p.current,
104+
tagPattern: tagPattern,
103105
);
104106

105107
// TODO(nweiz): Add some special handling for git repos that contain path

lib/src/language_version.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class LanguageVersion implements Comparable<LanguageVersion> {
6565

6666
bool get supportsWorkspaces => this >= firstVersionWithWorkspaces;
6767

68+
bool get supportsTagPattern => this >= firstVersionWithTagPattern;
69+
6870
bool get forbidsUnknownDescriptionKeys =>
6971
this >= firstVersionForbidingUnknownDescriptionKeys;
7072

@@ -105,6 +107,7 @@ class LanguageVersion implements Comparable<LanguageVersion> {
105107
static const firstVersionWithNullSafety = LanguageVersion(2, 12);
106108
static const firstVersionWithShorterHostedSyntax = LanguageVersion(2, 15);
107109
static const firstVersionWithWorkspaces = LanguageVersion(3, 5);
110+
static const firstVersionWithTagPattern = LanguageVersion(3, 9);
108111
static const firstVersionForbidingUnknownDescriptionKeys = LanguageVersion(
109112
3,
110113
7,

0 commit comments

Comments
 (0)