Skip to content

Add 'tag_pattern' feature to git dependencies #4427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a3b6b92
Add 'tag_pattern' feature
sigurdm Nov 15, 2024
a482697
Test for interdependencies
sigurdm Nov 15, 2024
4cb927e
Fix `pub add --git-tag-pattern`
sigurdm Nov 15, 2024
9bc9e65
Make `hasMultipleVersions` a property of the description
sigurdm Nov 15, 2024
9a6517e
{{version}}
sigurdm Mar 27, 2025
49978b4
merge
sigurdm Mar 27, 2025
71e0f0f
Format
sigurdm Mar 27, 2025
6124471
Validate tag_pattern early
sigurdm Mar 28, 2025
2c7fb43
not coming until 3.9...
sigurdm Mar 28, 2025
6960eb7
windows compatz2
sigurdm Mar 28, 2025
03ba0ef
Windows compatz in tests
sigurdm Apr 1, 2025
4e8de79
Fix test sdk version
sigurdm Apr 1, 2025
b57d89a
Escaping
sigurdm Apr 1, 2025
3d33d64
Update lib/src/source/git.dart
sigurdm May 12, 2025
8ff2d3f
Fix serializeForPubspec
sigurdm May 12, 2025
e630352
Merge
sigurdm May 12, 2025
3e98819
Don't print ref in pubspec lock when using tag_pattern
sigurdm May 12, 2025
8c97b20
Remove TODO
sigurdm May 12, 2025
da21216
Fill in missing dartdoc
sigurdm May 12, 2025
b576aed
Fix test expectation
sigurdm May 12, 2025
892e066
Use version constraint when adding a git dependency with a tag pattern
sigurdm May 12, 2025
b2231d1
Test for `add`ing with a `tag_pattern`
sigurdm May 12, 2025
0ffc5d1
Test shape of pubspec.lock
sigurdm May 12, 2025
cad4daf
More tests
sigurdm May 12, 2025
2ba15cb
Windows paths in test
sigurdm May 12, 2025
c5ca0bf
Merge remote-tracking branch 'origin/master' into git_version_by_tag
sigurdm May 13, 2025
520b299
Merge
sigurdm May 15, 2025
d2b4966
Address some of review
sigurdm May 15, 2025
e1d51ed
Only allow single {{version}} marker
sigurdm May 15, 2025
0fd0394
Revert hack
sigurdm May 15, 2025
bab5b82
lints
sigurdm May 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/src/command/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ For example (follow the same format including spaces):
help: 'Path of git package in repository',
hide: true,
);
argParser.addOption(
'git-tag-pattern',
help: 'The tag-pattern to search for versions in repository',
hide: true,
);
argParser.addOption(
'hosted-url',
help: 'URL of package host server',
Expand Down Expand Up @@ -543,6 +548,11 @@ Specify multiple sdk packages with descriptors.''');
if (gitUrl == null) {
usageException('The `--git-url` is required for git dependencies.');
}
if (argResults.gitRef != null && argResults.tagPattern != null) {
usageException(
'Cannot provide both `--git-ref` and `--git-tag-pattern`.',
);
}

/// Process the git options to return the simplest representation to be
/// added to the pubspec.
Expand All @@ -554,6 +564,7 @@ Specify multiple sdk packages with descriptors.''');
containingDir: p.current,
ref: argResults.gitRef,
path: argResults.gitPath,
tagPattern: argResults.tagPattern,
),
);
} on FormatException catch (e) {
Expand Down Expand Up @@ -789,6 +800,8 @@ extension on ArgResults {
bool get isDryRun => flag('dry-run');
String? get gitUrl => this['git-url'] as String?;
String? get gitPath => this['git-path'] as String?;
String? get tagPattern => this['git-tag-pattern'] as String?;

String? get gitRef => this['git-ref'] as String?;
String? get hostedUrl => this['hosted-url'] as String?;
String? get path => this['path'] as String?;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/command/dependency_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class DependencyServicesApplyCommand extends PubCommand {
} else if (targetRevision != null &&
(lockFileYaml['packages'] as Map).containsKey(targetPackage)) {
final ref = entrypoint.lockFile.packages[targetPackage]!.toRef();

final currentDescription = ref.description as GitDescription;
final updatedRef = PackageRef(
targetPackage,
Expand All @@ -432,6 +433,7 @@ class DependencyServicesApplyCommand extends PubCommand {
path: currentDescription.path,
ref: targetRevision,
containingDir: directory,
tagPattern: currentDescription.tagPattern,
),
);
final versions = await cache.getVersions(updatedRef);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/global_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ class GlobalPackages {
required bool overwriteBinStubs,
String? path,
String? ref,
String? tagPattern,
}) async {
final name = await cache.git.getPackageNameFromRepo(
repo,
ref,
path,
cache,
relativeTo: p.current,
tagPattern: tagPattern,
);

// TODO(nweiz): Add some special handling for git repos that contain path
Expand Down
3 changes: 3 additions & 0 deletions lib/src/language_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class LanguageVersion implements Comparable<LanguageVersion> {

bool get supportsWorkspaces => this >= firstVersionWithWorkspaces;

bool get supportsTagPattern => this >= firstVersionWithTagPattern;

bool get forbidsUnknownDescriptionKeys =>
this >= firstVersionForbidingUnknownDescriptionKeys;

Expand Down Expand Up @@ -105,6 +107,7 @@ class LanguageVersion implements Comparable<LanguageVersion> {
static const firstVersionWithNullSafety = LanguageVersion(2, 12);
static const firstVersionWithShorterHostedSyntax = LanguageVersion(2, 15);
static const firstVersionWithWorkspaces = LanguageVersion(3, 5);
static const firstVersionWithTagPattern = LanguageVersion(3, 9);
static const firstVersionForbidingUnknownDescriptionKeys = LanguageVersion(
3,
7,
Expand Down
Loading