mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Allow 'flutter create' in dev and example directories (#74932)
This commit is contained in:
parent
234952cf29
commit
bf248fade2
@ -249,10 +249,16 @@ abstract class CreateBase extends FlutterCommand {
|
||||
@protected
|
||||
void validateProjectDir({bool overwrite = false}) {
|
||||
if (globals.fs.path.isWithin(flutterRoot, projectDirPath)) {
|
||||
throwToolExit(
|
||||
'Cannot create a project within the Flutter SDK. '
|
||||
"Target directory '$projectDirPath' is within the Flutter SDK at '$flutterRoot'.",
|
||||
exitCode: 2);
|
||||
// Make exception for dev and examples to facilitate example project development.
|
||||
final String examplesDirectory = globals.fs.path.join(flutterRoot, 'examples');
|
||||
final String devDirectory = globals.fs.path.join(flutterRoot, 'dev');
|
||||
if (!globals.fs.path.isWithin(examplesDirectory, projectDirPath) &&
|
||||
!globals.fs.path.isWithin(devDirectory, projectDirPath)) {
|
||||
throwToolExit(
|
||||
'Cannot create a project within the Flutter SDK. '
|
||||
"Target directory '$projectDirPath' is within the Flutter SDK at '$flutterRoot'.",
|
||||
exitCode: 2);
|
||||
}
|
||||
}
|
||||
|
||||
// If the destination directory is actually a file, then we refuse to
|
||||
|
||||
@ -186,6 +186,31 @@ void main() {
|
||||
...noColorTerminalOverride,
|
||||
});
|
||||
|
||||
testUsingContext('cannot create a project in flutter root', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', globals.platform.isWindows ? 'flutter.bat' : 'flutter');
|
||||
final ProcessResult exec = await Process.run(
|
||||
flutterBin,
|
||||
<String>[
|
||||
'create',
|
||||
'flutter_project',
|
||||
],
|
||||
workingDirectory: Cache.flutterRoot,
|
||||
);
|
||||
expect(exec.exitCode, 2);
|
||||
expect(exec.stderr, contains('Cannot create a project within the Flutter SDK'));
|
||||
}, overrides: <Type, Generator>{
|
||||
Pub: () => Pub(
|
||||
fileSystem: globals.fs,
|
||||
logger: globals.logger,
|
||||
processManager: globals.processManager,
|
||||
usage: globals.flutterUsage,
|
||||
botDetector: globals.botDetector,
|
||||
platform: globals.platform,
|
||||
),
|
||||
...noColorTerminalOverride,
|
||||
});
|
||||
|
||||
testUsingContext('Will create an app project if non-empty non-project directory exists without .metadata', () async {
|
||||
await projectDir.absolute.childDirectory('blag').create(recursive: true);
|
||||
await projectDir.absolute.childDirectory('.idea').create(recursive: true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user