diff --git a/docs/configuration/overview.mdx b/docs/configuration/overview.mdx index 84a4ea72..476ab999 100644 --- a/docs/configuration/overview.mdx +++ b/docs/configuration/overview.mdx @@ -333,3 +333,14 @@ Whether to generate and print a link to the prefilled release creation page for each package after versioning. Defaults to `false`. [glob]: https://docs.python.org/3/library/glob.html + +### `command/version/fetchTags` + +Whether to fetch tags from the `origin` remote before versioning. Defaults to +`true`. + +```yaml +command: + version: + fetchTags: false +``` diff --git a/packages/melos/lib/src/commands/version.dart b/packages/melos/lib/src/commands/version.dart index 86682246..bc3a24d4 100644 --- a/packages/melos/lib/src/commands/version.dart +++ b/packages/melos/lib/src/commands/version.dart @@ -114,6 +114,10 @@ mixin _VersionMixin on _RunMixin { final commitMessageTemplate = Template(message, delimiters: '{ }'); + if (config.commands.version.fetchTags) { + await gitFetchTags(workingDirectory: workspace.path, logger: logger); + } + final packageCommits = await _getPackageCommits( workspace, versionPrivatePackages: versionPrivatePackages, diff --git a/packages/melos/lib/src/common/git.dart b/packages/melos/lib/src/common/git.dart index 54422891..2e6ee936 100644 --- a/packages/melos/lib/src/common/git.dart +++ b/packages/melos/lib/src/common/git.dart @@ -224,6 +224,17 @@ Future gitLatestTagForPackage( return tags.first; } +Future gitFetchTags({ + required String workingDirectory, + required MelosLogger logger, +}) async { + await gitExecuteCommand( + arguments: ['fetch', '--tags'], + workingDirectory: workingDirectory, + logger: logger, + ); +} + /// Stage files matching the specified file pattern for committing. Future gitAdd( String filePattern, { diff --git a/packages/melos/lib/src/workspace_configs.dart b/packages/melos/lib/src/workspace_configs.dart index 75cfeeb1..876ee7f8 100644 --- a/packages/melos/lib/src/workspace_configs.dart +++ b/packages/melos/lib/src/workspace_configs.dart @@ -395,6 +395,7 @@ class VersionCommandConfigs { this.updateGitTagRefs = false, this.releaseUrl = false, List? aggregateChangelogs, + this.fetchTags = true, }) : _aggregateChangelogs = aggregateChangelogs; factory VersionCommandConfigs.fromYaml( @@ -489,6 +490,12 @@ class VersionCommandConfigs { aggregateChangelogs.add(changelogConfig); } + final fetchTags = assertKeyIsA( + key: 'fetchTags', + map: yaml, + path: 'command/version', + ); + return VersionCommandConfigs( branch: branch, message: message, @@ -498,6 +505,7 @@ class VersionCommandConfigs { updateGitTagRefs: updateGitTagRefs ?? false, releaseUrl: releaseUrl ?? false, aggregateChangelogs: aggregateChangelogs, + fetchTags: fetchTags ?? true, ); } @@ -534,6 +542,9 @@ class VersionCommandConfigs { final List? _aggregateChangelogs; + /// Whether to fetch tags from the `origin` remote before versioning. + final bool fetchTags; + Map toJson() { return { if (branch != null) 'branch': branch, @@ -544,6 +555,7 @@ class VersionCommandConfigs { 'updateGitTagRefs': updateGitTagRefs, 'aggregateChangelogs': aggregateChangelogs.map((config) => config.toJson()).toList(), + 'fetchTags': fetchTags, }; } @@ -559,7 +571,8 @@ class VersionCommandConfigs { other.updateGitTagRefs == updateGitTagRefs && other.releaseUrl == releaseUrl && const DeepCollectionEquality() - .equals(other.aggregateChangelogs, aggregateChangelogs); + .equals(other.aggregateChangelogs, aggregateChangelogs) && + other.fetchTags == fetchTags; @override int get hashCode => @@ -571,7 +584,8 @@ class VersionCommandConfigs { linkToCommits.hashCode ^ updateGitTagRefs.hashCode ^ releaseUrl.hashCode ^ - const DeepCollectionEquality().hash(aggregateChangelogs); + const DeepCollectionEquality().hash(aggregateChangelogs) ^ + fetchTags.hashCode; @override String toString() { @@ -585,6 +599,7 @@ VersionCommandConfigs( updateGitTagRefs: $updateGitTagRefs, releaseUrl: $releaseUrl, aggregateChangelogs: $aggregateChangelogs, + fetchTags: $fetchTags, )'''; } }