Skip to content
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

feat: Add git-commit-version flag to control commit creation #628

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 13 additions & 4 deletions packages/melos/lib/src/command_runner/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ class VersionCommand extends MelosCommand {
'git-tag-version',
abbr: 't',
defaultsTo: true,
help:
'By default, melos version will commit changes to pubspec.yaml files '
'and tag the release. Pass --no-git-tag-version to disable the '
'behaviour.',
help: 'By default, melos version will tag the release. Pass '
'--no-git-tag-version to disable the behaviour.',
);
argParser.addFlag(
'git-commit-version',
abbr: 'C',
defaultsTo: true,
help: 'By default, melos version will commit changes to pubspec.yaml and '
'changelog files. Pass --no-git-commit-version to disable the '
'behaviour, passing this also implies --no-git-tag-version.',
);
argParser.addFlag(
'release-url',
Expand Down Expand Up @@ -167,6 +173,7 @@ class VersionCommand extends MelosCommand {
final updateDependentsConstraints =
argResults!['dependent-constraints'] as bool;
final tag = argResults!['git-tag-version'] as bool;
final commit = argResults!['git-commit-version'] as bool;
final releaseUrl = argResults!.optional('release-url') as bool?;
final changelog = argResults!['changelog'] as bool;
final commitMessage =
Expand Down Expand Up @@ -196,6 +203,7 @@ class VersionCommand extends MelosCommand {
manualVersions: {packageName: versionChange},
force: force,
gitTag: tag,
gitCommit: commit,
releaseUrl: releaseUrl,
updateChangelog: changelog,
updateDependentsConstraints: updateDependentsConstraints,
Expand Down Expand Up @@ -238,6 +246,7 @@ class VersionCommand extends MelosCommand {
packageFilters: parsePackageFilters(config.path),
force: force,
gitTag: tag,
gitCommit: commit,
releaseUrl: releaseUrl,
updateChangelog: changelog,
updateDependentsConstraints: updateDependentsConstraints,
Expand Down
29 changes: 17 additions & 12 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mixin _VersionMixin on _RunMixin {
bool updateDependentsConstraints = true,
bool updateDependentsVersions = true,
bool gitTag = true,
bool gitCommit = true,
bool? releaseUrl,
String? message,
bool force = false,
Expand Down Expand Up @@ -59,6 +60,7 @@ mixin _VersionMixin on _RunMixin {
updateDependentsConstraints: updateDependentsConstraints,
updateDependentsVersions: updateDependentsVersions,
gitTag: gitTag,
gitCommit: gitCommit,
releaseUrl: releaseUrl,
message: message,
force: force,
Expand All @@ -81,6 +83,7 @@ mixin _VersionMixin on _RunMixin {
bool updateDependentsConstraints = true,
bool updateDependentsVersions = true,
bool gitTag = true,
bool gitCommit = true,
bool? releaseUrl,
String? message,
bool force = false,
Expand Down Expand Up @@ -354,19 +357,21 @@ mixin _VersionMixin on _RunMixin {
logger.newLine();
}

await _gitStageChanges(
workspace,
pendingPackageUpdates,
updateDependentsVersions: updateDependentsVersions,
);
await _gitCommitChanges(
workspace,
pendingPackageUpdates,
commitMessageTemplate,
updateDependentsVersions: updateDependentsVersions,
);
if (gitCommit) {
await _gitStageChanges(
workspace,
pendingPackageUpdates,
updateDependentsVersions: updateDependentsVersions,
);
await _gitCommitChanges(
workspace,
pendingPackageUpdates,
commitMessageTemplate,
updateDependentsVersions: updateDependentsVersions,
);
}

if (gitTag) {
if (gitTag && gitCommit) {
await _gitTagChanges(
pendingPackageUpdates,
updateDependentsVersions: updateDependentsVersions,
Expand Down
Loading