Skip to content

Commit e5a89d5

Browse files
stuartmorganamantoux
authored andcommitted
[flutter_plugin_tools] Adjust diff logging (flutter#4312)
1 parent 1e3fbfa commit e5a89d5

5 files changed

+28
-10
lines changed

script/tool/lib/src/common/git_version_finder.dart

+12-9
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import 'package:yaml/yaml.dart';
1111
/// Finding diffs based on `baseGitDir` and `baseSha`.
1212
class GitVersionFinder {
1313
/// Constructor
14-
GitVersionFinder(this.baseGitDir, this.baseSha);
14+
GitVersionFinder(this.baseGitDir, String? baseSha) : _baseSha = baseSha;
1515

1616
/// The top level directory of the git repo.
1717
///
1818
/// That is where the .git/ folder exists.
1919
final GitDir baseGitDir;
2020

2121
/// The base sha used to get diff.
22-
final String? baseSha;
22+
String? _baseSha;
2323

2424
static bool _isPubspec(String file) {
2525
return file.trim().endsWith('pubspec.yaml');
@@ -32,10 +32,9 @@ class GitVersionFinder {
3232

3333
/// Get a list of all the changed files.
3434
Future<List<String>> getChangedFiles() async {
35-
final String baseSha = await _getBaseSha();
35+
final String baseSha = await getBaseSha();
3636
final io.ProcessResult changedFilesCommand = await baseGitDir
3737
.runCommand(<String>['diff', '--name-only', baseSha, 'HEAD']);
38-
print('Determine diff with base sha: $baseSha');
3938
final String changedFilesStdout = changedFilesCommand.stdout.toString();
4039
if (changedFilesStdout.isEmpty) {
4140
return <String>[];
@@ -49,7 +48,7 @@ class GitVersionFinder {
4948
/// at the revision of `gitRef` (defaulting to the base if not provided).
5049
Future<Version?> getPackageVersion(String pubspecPath,
5150
{String? gitRef}) async {
52-
final String ref = gitRef ?? (await _getBaseSha());
51+
final String ref = gitRef ?? (await getBaseSha());
5352

5453
io.ProcessResult gitShow;
5554
try {
@@ -63,9 +62,11 @@ class GitVersionFinder {
6362
return versionString == null ? null : Version.parse(versionString);
6463
}
6564

66-
Future<String> _getBaseSha() async {
67-
if (baseSha != null && baseSha!.isNotEmpty) {
68-
return baseSha!;
65+
/// Returns the base used to diff against.
66+
Future<String> getBaseSha() async {
67+
String? baseSha = _baseSha;
68+
if (baseSha != null && baseSha.isNotEmpty) {
69+
return baseSha;
6970
}
7071

7172
io.ProcessResult baseShaFromMergeBase = await baseGitDir.runCommand(
@@ -76,6 +77,8 @@ class GitVersionFinder {
7677
baseShaFromMergeBase = await baseGitDir
7778
.runCommand(<String>['merge-base', 'FETCH_HEAD', 'HEAD']);
7879
}
79-
return (baseShaFromMergeBase.stdout as String).trim();
80+
baseSha = (baseShaFromMergeBase.stdout as String).trim();
81+
_baseSha = baseSha;
82+
return baseSha;
8083
}
8184
}

script/tool/lib/src/common/plugin_command.dart

+3
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ abstract class PluginCommand extends Command<void> {
314314

315315
if (runOnChangedPackages) {
316316
final GitVersionFinder gitVersionFinder = await retrieveVersionFinder();
317+
final String baseSha = await gitVersionFinder.getBaseSha();
318+
print(
319+
'Running for all packages that have changed relative to "$baseSha"\n');
317320
final List<String> changedFiles =
318321
await gitVersionFinder.getChangedFiles();
319322
if (!_changesRequireFullTest(changedFiles)) {

script/tool/lib/src/publish_plugin_command.dart

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ class PublishPluginCommand extends PackageLoopingCommand {
159159
Stream<PackageEnumerationEntry> getPackagesToProcess() async* {
160160
if (getBoolArg(_allChangedFlag)) {
161161
final GitVersionFinder gitVersionFinder = await retrieveVersionFinder();
162+
final String baseSha = await gitVersionFinder.getBaseSha();
163+
print(
164+
'Publishing all packages that have changed relative to "$baseSha"\n');
162165
final List<String> changedPubspecs =
163166
await gitVersionFinder.getChangedPubSpecs();
164167

script/tool/test/common/plugin_command_test.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,19 @@ packages/plugin1/CHANGELOG
398398
];
399399
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
400400
createFakePlugin('plugin2', packagesDir);
401-
await runCapturingPrint(runner, <String>[
401+
final List<String> output = await runCapturingPrint(runner, <String>[
402402
'sample',
403403
'--base-sha=master',
404404
'--run-on-changed-packages'
405405
]);
406406

407+
expect(
408+
output,
409+
containsAllInOrder(<Matcher>[
410+
contains(
411+
'Running for all packages that have changed relative to "master"'),
412+
]));
413+
407414
expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
408415
});
409416

script/tool/test/publish_plugin_command_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ void main() {
466466
expect(
467467
output,
468468
containsAllInOrder(<Matcher>[
469+
contains(
470+
'Publishing all packages that have changed relative to "HEAD~"'),
469471
contains('Running `pub publish ` in ${pluginDir1.path}...'),
470472
contains('Running `pub publish ` in ${pluginDir2.path}...'),
471473
contains('plugin1 - \x1B[32mpublished\x1B[0m'),

0 commit comments

Comments
 (0)