[tool] Update .gitignore templates to include .flutter-plugins files (#152950)

Fixes https://github.com/flutter/flutter/issues/152793
This commit is contained in:
Rexios 2024-09-04 16:54:24 -04:00 committed by GitHub
parent b9ae1f1bd3
commit 6abef22251
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 61 additions and 19 deletions

View File

@ -26,4 +26,6 @@ migrate_working_dir/
/pubspec.lock /pubspec.lock
**/doc/api/ **/doc/api/
.dart_tool/ .dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
build/ build/

View File

@ -26,5 +26,7 @@ migrate_working_dir/
/pubspec.lock /pubspec.lock
**/doc/api/ **/doc/api/
.dart_tool/ .dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages .packages
build/ build/

View File

@ -28,4 +28,6 @@ migrate_working_dir/
/pubspec.lock /pubspec.lock
**/doc/api/ **/doc/api/
.dart_tool/ .dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
build/ build/

View File

@ -66,6 +66,12 @@ const String samplesIndexJson = '''
{ "id": "sample2" } { "id": "sample2" }
]'''; ]''';
/// These files are generated for all project types.
const List<String> flutterPluginsIgnores = <String>[
'.flutter-plugins',
'.flutter-plugins-dependencies',
];
void main() { void main() {
late Directory tempDir; late Directory tempDir;
late Directory projectDir; late Directory projectDir;
@ -177,6 +183,7 @@ void main() {
'ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png', 'ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png',
'lib/main.dart', 'lib/main.dart',
], ],
expectedGitignoreLines: flutterPluginsIgnores,
); );
expect(logger.statusText, contains('In order to run your application, type:')); expect(logger.statusText, contains('In order to run your application, type:'));
// Check that we're telling them about documentation // Check that we're telling them about documentation
@ -246,6 +253,7 @@ void main() {
'pubspec.yaml', 'pubspec.yaml',
'README.md', 'README.md',
], ],
expectedGitignoreLines: flutterPluginsIgnores,
); );
return _runFlutterTest(projectDir); return _runFlutterTest(projectDir);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
@ -288,22 +296,28 @@ void main() {
}); });
testUsingContext('creates a module project correctly', () async { testUsingContext('creates a module project correctly', () async {
await _createAndAnalyzeProject(projectDir, <String>[ await _createAndAnalyzeProject(
'--template=module', projectDir,
], <String>[ <String>[
'.android/app/', '--template=module',
'.gitignore', ],
'.ios/Flutter', <String>[
'.metadata', '.android/app/',
'analysis_options.yaml', '.gitignore',
'lib/main.dart', '.ios/Flutter',
'pubspec.yaml', '.metadata',
'README.md', 'analysis_options.yaml',
'test/widget_test.dart', 'lib/main.dart',
], unexpectedPaths: <String>[ 'pubspec.yaml',
'android/', 'README.md',
'ios/', 'test/widget_test.dart',
]); ],
unexpectedPaths: <String>[
'android/',
'ios/',
],
expectedGitignoreLines: flutterPluginsIgnores,
);
return _runFlutterTest(projectDir); return _runFlutterTest(projectDir);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Pub: () => Pub.test( Pub: () => Pub.test(
@ -568,6 +582,7 @@ void main() {
'linux/flutter/generated_plugins.cmake', 'linux/flutter/generated_plugins.cmake',
'macos/Flutter/GeneratedPluginRegistrant.swift', 'macos/Flutter/GeneratedPluginRegistrant.swift',
], ],
expectedGitignoreLines: flutterPluginsIgnores,
); );
return _runFlutterTest(projectDir); return _runFlutterTest(projectDir);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
@ -599,6 +614,7 @@ void main() {
'example/android/app/src/main/java/com/example/flutter_project_example/MainActivity.java', 'example/android/app/src/main/java/com/example/flutter_project_example/MainActivity.java',
'lib/flutter_project_web.dart', 'lib/flutter_project_web.dart',
], ],
expectedGitignoreLines: flutterPluginsIgnores,
); );
return _runFlutterTest(projectDir.childDirectory('example')); return _runFlutterTest(projectDir.childDirectory('example'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
@ -2148,6 +2164,7 @@ void main() {
'ios/Flutter/AppFrameworkInfo.plist', 'ios/Flutter/AppFrameworkInfo.plist',
], ],
unexpectedPaths: <String>['test'], unexpectedPaths: <String>['test'],
expectedGitignoreLines: flutterPluginsIgnores,
); );
expect(projectDir.childDirectory('lib').childFile('main.dart').readAsStringSync(), expect(projectDir.childDirectory('lib').childFile('main.dart').readAsStringSync(),
contains("Text('Hello World!')")); contains("Text('Hello World!')"));
@ -2236,6 +2253,7 @@ void main() {
'ios/Flutter/AppFrameworkInfo.plist', 'ios/Flutter/AppFrameworkInfo.plist',
], ],
unexpectedPaths: <String>['test'], unexpectedPaths: <String>['test'],
expectedGitignoreLines: flutterPluginsIgnores,
); );
expect(projectDir.childDirectory('lib').childFile('main.dart').readAsStringSync(), expect(projectDir.childDirectory('lib').childFile('main.dart').readAsStringSync(),
contains('void main() {}')); contains('void main() {}'));
@ -3915,6 +3933,7 @@ Future<void> _createProject(
List<String> createArgs, List<String> createArgs,
List<String> expectedPaths, { List<String> expectedPaths, {
List<String> unexpectedPaths = const <String>[], List<String> unexpectedPaths = const <String>[],
List<String> expectedGitignoreLines = const <String>[],
}) async { }) async {
Cache.flutterRoot = '../..'; Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand(); final CreateCommand command = CreateCommand();
@ -3930,7 +3949,7 @@ Future<void> _createProject(
return globals.fs.typeSync(fullPath) != FileSystemEntityType.notFound; return globals.fs.typeSync(fullPath) != FileSystemEntityType.notFound;
} }
final List<String> failures = <String>[ final List<String> pathFailures = <String>[
for (final String path in expectedPaths) for (final String path in expectedPaths)
if (!pathExists(path)) if (!pathExists(path))
'Path "$path" does not exist.', 'Path "$path" does not exist.',
@ -3938,7 +3957,17 @@ Future<void> _createProject(
if (pathExists(path)) if (pathExists(path))
'Path "$path" exists when it shouldn\'t.', 'Path "$path" exists when it shouldn\'t.',
]; ];
expect(failures, isEmpty, reason: failures.join('\n')); expect(pathFailures, isEmpty, reason: pathFailures.join('\n'));
final String gitignorePath = globals.fs.path.join(dir.path, '.gitignore');
final List<String> gitignore = globals.fs.file(gitignorePath).readAsLinesSync();
final List<String> gitignoreFailures = <String>[
for (final String line in expectedGitignoreLines)
if (!gitignore.contains(line))
'Expected .gitignore to contain "$line".',
];
expect(gitignoreFailures, isEmpty, reason: gitignoreFailures.join('\n'));
} }
Future<void> _createAndAnalyzeProject( Future<void> _createAndAnalyzeProject(
@ -3946,8 +3975,15 @@ Future<void> _createAndAnalyzeProject(
List<String> createArgs, List<String> createArgs,
List<String> expectedPaths, { List<String> expectedPaths, {
List<String> unexpectedPaths = const <String>[], List<String> unexpectedPaths = const <String>[],
List<String> expectedGitignoreLines = const <String>[],
}) async { }) async {
await _createProject(dir, createArgs, expectedPaths, unexpectedPaths: unexpectedPaths); await _createProject(
dir,
createArgs,
expectedPaths,
unexpectedPaths: unexpectedPaths,
expectedGitignoreLines: expectedGitignoreLines,
);
await _analyzeProject(dir.path); await _analyzeProject(dir.path);
} }