Skip to content

Commit

Permalink
feat: Add git-commit-version flag to control commit creation (#628)
Browse files Browse the repository at this point in the history
* fix: Create commit when `--no-git-tag-version` is used

* feat: Add `git-commit-version` flag to control commit creation

* No tag should be created when no commit is created

* Update packages/melos/lib/src/command_runner/version.dart

Co-authored-by: Mike Diarmid <[email protected]>

* fix line length

---------

Co-authored-by: Mike Diarmid <[email protected]>
  • Loading branch information
spydon and Salakar authored Jan 11, 2024
1 parent b89133d commit cca7187
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
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

0 comments on commit cca7187

Please sign in to comment.