Delete flutter_migrate code (#114253)
This commit is contained in:
@@ -1,146 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/migrate.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/migrate/migrate_utils.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
late BufferLogger logger;
|
||||
late Platform platform;
|
||||
late Terminal terminal;
|
||||
late ProcessManager processManager;
|
||||
late Directory appDir;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = globals.localFileSystem;
|
||||
appDir = fileSystem.systemTempDirectory.createTempSync('apptestdir');
|
||||
logger = BufferLogger.test();
|
||||
platform = FakePlatform();
|
||||
terminal = Terminal.test();
|
||||
processManager = globals.processManager;
|
||||
});
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(appDir);
|
||||
});
|
||||
|
||||
testUsingContext('abandon deletes staging directory', () async {
|
||||
final MigrateCommand command = MigrateCommand(
|
||||
verbose: true,
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
terminal: terminal,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
);
|
||||
final Directory stagingDir = appDir.childDirectory(kDefaultMigrateStagingDirectoryName);
|
||||
appDir.childFile('lib/main.dart').createSync(recursive: true);
|
||||
final File pubspecOriginal = appDir.childFile('pubspec.yaml');
|
||||
pubspecOriginal.createSync();
|
||||
pubspecOriginal.writeAsStringSync('''
|
||||
name: originalname
|
||||
description: A new Flutter project.
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: '>=2.18.0-58.0.dev <3.0.0'
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
uses-material-design: true''', flush: true);
|
||||
|
||||
expect(stagingDir.existsSync(), false);
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'abandon',
|
||||
'--staging-directory=${stagingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
expect(logger.errorText, contains('Provided staging directory'));
|
||||
expect(logger.errorText, contains('migrate_staging_dir` does not exist or is not valid.'));
|
||||
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'abandon',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
expect(logger.statusText, contains('No migration in progress. Start a new migration with:'));
|
||||
|
||||
final File pubspecModified = stagingDir.childFile('pubspec.yaml');
|
||||
pubspecModified.createSync(recursive: true);
|
||||
pubspecModified.writeAsStringSync('''
|
||||
name: newname
|
||||
description: new description of the test project
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: '>=2.18.0-58.0.dev <3.0.0'
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
uses-material-design: false
|
||||
EXTRALINE''', flush: true);
|
||||
|
||||
final File addedFile = stagingDir.childFile('added.file');
|
||||
addedFile.createSync(recursive: true);
|
||||
addedFile.writeAsStringSync('new file contents');
|
||||
|
||||
final File manifestFile = stagingDir.childFile('.migrate_manifest');
|
||||
manifestFile.createSync(recursive: true);
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
- pubspec.yaml
|
||||
conflict_files:
|
||||
added_files:
|
||||
- added.file
|
||||
deleted_files:
|
||||
''');
|
||||
|
||||
expect(appDir.childFile('lib/main.dart').existsSync(), true);
|
||||
|
||||
expect(stagingDir.existsSync(), true);
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'abandon',
|
||||
'--staging-directory=${stagingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
'--force',
|
||||
]
|
||||
);
|
||||
expect(logger.statusText, contains('Abandon complete. Start a new migration with:'));
|
||||
expect(stagingDir.existsSync(), false);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
Platform: () => platform,
|
||||
});
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/migrate.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/migrate/migrate_utils.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
late BufferLogger logger;
|
||||
late Platform platform;
|
||||
late Terminal terminal;
|
||||
late ProcessManager processManager;
|
||||
late Directory appDir;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = globals.localFileSystem;
|
||||
appDir = fileSystem.systemTempDirectory.createTempSync('apptestdir');
|
||||
logger = BufferLogger.test();
|
||||
platform = FakePlatform();
|
||||
terminal = Terminal.test();
|
||||
processManager = globals.processManager;
|
||||
});
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(appDir);
|
||||
});
|
||||
|
||||
testUsingContext('Apply produces all outputs', () async {
|
||||
final MigrateCommand command = MigrateCommand(
|
||||
verbose: true,
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
terminal: terminal,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
);
|
||||
final Directory workingDir = appDir.childDirectory(kDefaultMigrateStagingDirectoryName);
|
||||
appDir.childFile('lib/main.dart').createSync(recursive: true);
|
||||
final File pubspecOriginal = appDir.childFile('pubspec.yaml');
|
||||
pubspecOriginal.createSync();
|
||||
pubspecOriginal.writeAsStringSync('''
|
||||
name: originalname
|
||||
description: A new Flutter project.
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: '>=2.18.0-58.0.dev <3.0.0'
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
uses-material-design: true''', flush: true);
|
||||
|
||||
final File gitignore = appDir.childFile('.gitignore');
|
||||
gitignore.createSync();
|
||||
gitignore.writeAsStringSync(kDefaultMigrateStagingDirectoryName, flush: true);
|
||||
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'apply',
|
||||
'--staging-directory=${workingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
expect(logger.statusText, contains('Project is not a git repo. Please initialize a git repo and try again.'));
|
||||
|
||||
await processManager.run(<String>['git', 'init'], workingDirectory: appDir.path);
|
||||
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'apply',
|
||||
'--staging-directory=${workingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
expect(logger.statusText, contains('No migration in progress'));
|
||||
|
||||
final File pubspecModified = workingDir.childFile('pubspec.yaml');
|
||||
pubspecModified.createSync(recursive: true);
|
||||
pubspecModified.writeAsStringSync('''
|
||||
name: newname
|
||||
description: new description of the test project
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: '>=2.18.0-58.0.dev <3.0.0'
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
uses-material-design: false
|
||||
# EXTRALINE:''', flush: true);
|
||||
|
||||
final File addedFile = workingDir.childFile('added.file');
|
||||
addedFile.createSync(recursive: true);
|
||||
addedFile.writeAsStringSync('new file contents');
|
||||
|
||||
final File manifestFile = workingDir.childFile('.migrate_manifest');
|
||||
manifestFile.createSync(recursive: true);
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
- pubspec.yaml
|
||||
conflict_files:
|
||||
- conflict/conflict.file
|
||||
added_files:
|
||||
- added.file
|
||||
deleted_files:
|
||||
''');
|
||||
|
||||
// Add conflict file
|
||||
final File conflictFile = workingDir.childDirectory('conflict').childFile('conflict.file');
|
||||
conflictFile.createSync(recursive: true);
|
||||
conflictFile.writeAsStringSync('''
|
||||
line1
|
||||
<<<<<<< /conflcit/conflict.file
|
||||
line2
|
||||
=======
|
||||
linetwo
|
||||
>>>>>>> /var/folders/md/gm0zgfcj07vcsj6jkh_mp_wh00ff02/T/flutter_tools.4Xdep8/generatedTargetTemplatetlN44S/conflict/conflict.file
|
||||
line3
|
||||
''', flush: true);
|
||||
|
||||
final File conflictFileOriginal = appDir.childDirectory('conflict').childFile('conflict.file');
|
||||
conflictFileOriginal.createSync(recursive: true);
|
||||
conflictFileOriginal.writeAsStringSync('''
|
||||
line1
|
||||
line2
|
||||
line3
|
||||
''', flush: true);
|
||||
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'apply',
|
||||
'--staging-directory=${workingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
expect(logger.statusText, contains(r'''
|
||||
Added files:
|
||||
- added.file
|
||||
Modified files:
|
||||
- pubspec.yaml
|
||||
Unable to apply migration. The following files in the migration working directory still have unresolved conflicts:
|
||||
- conflict/conflict.file
|
||||
Conflicting files found. Resolve these conflicts and try again.
|
||||
Guided conflict resolution wizard:
|
||||
|
||||
$ flutter migrate resolve-conflicts'''));
|
||||
|
||||
conflictFile.writeAsStringSync('''
|
||||
line1
|
||||
linetwo
|
||||
line3
|
||||
''', flush: true);
|
||||
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'apply',
|
||||
'--staging-directory=${workingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
expect(logger.statusText, contains('There are uncommitted changes in your project. Please git commit, abandon, or stash your changes before trying again.'));
|
||||
|
||||
await processManager.run(<String>['git', 'add', '.'], workingDirectory: appDir.path);
|
||||
await processManager.run(<String>['git', 'commit', '-m', 'Initial commit'], workingDirectory: appDir.path);
|
||||
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'apply',
|
||||
'--staging-directory=${workingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
expect(logger.statusText, contains(r'''
|
||||
Added files:
|
||||
- added.file
|
||||
Modified files:
|
||||
- conflict/conflict.file
|
||||
- pubspec.yaml
|
||||
|
||||
Applying migration.
|
||||
Modifying 3 files.
|
||||
Writing pubspec.yaml
|
||||
Writing conflict/conflict.file
|
||||
Writing added.file
|
||||
Updating .migrate_configs
|
||||
Migration complete. You may use commands like `git status`, `git diff` and `git restore <file>` to continue working with the migrated files.'''));
|
||||
|
||||
expect(pubspecOriginal.readAsStringSync(), contains('# EXTRALINE'));
|
||||
expect(conflictFileOriginal.readAsStringSync(), contains('linetwo'));
|
||||
expect(appDir.childFile('added.file').existsSync(), true);
|
||||
expect(appDir.childFile('added.file').readAsStringSync(), contains('new file contents'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
Platform: () => platform,
|
||||
});
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/migrate.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/migrate/migrate_utils.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/test_flutter_command_runner.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
late BufferLogger logger;
|
||||
late Platform platform;
|
||||
late Terminal terminal;
|
||||
late ProcessManager processManager;
|
||||
late Directory appDir;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = globals.localFileSystem;
|
||||
appDir = fileSystem.systemTempDirectory.createTempSync('apptestdir');
|
||||
logger = BufferLogger.test();
|
||||
platform = FakePlatform();
|
||||
terminal = Terminal.test();
|
||||
processManager = globals.processManager;
|
||||
});
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(appDir);
|
||||
});
|
||||
|
||||
testUsingContext('Status produces all outputs', () async {
|
||||
final MigrateCommand command = MigrateCommand(
|
||||
verbose: true,
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
terminal: terminal,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
);
|
||||
final Directory stagingDir = appDir.childDirectory(kDefaultMigrateStagingDirectoryName);
|
||||
final File pubspecOriginal = appDir.childFile('pubspec.yaml');
|
||||
pubspecOriginal.createSync();
|
||||
pubspecOriginal.writeAsStringSync('''
|
||||
name: originalname
|
||||
description: A new Flutter project.
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: '>=2.18.0-58.0.dev <3.0.0'
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
uses-material-design: true''', flush: true);
|
||||
|
||||
final File pubspecModified = stagingDir.childFile('pubspec.yaml');
|
||||
pubspecModified.createSync(recursive: true);
|
||||
pubspecModified.writeAsStringSync('''
|
||||
name: newname
|
||||
description: new description of the test project
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: '>=2.18.0-58.0.dev <3.0.0'
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
uses-material-design: false
|
||||
EXTRALINE''', flush: true);
|
||||
|
||||
final File addedFile = stagingDir.childFile('added.file');
|
||||
addedFile.createSync(recursive: true);
|
||||
addedFile.writeAsStringSync('new file contents');
|
||||
|
||||
final File manifestFile = stagingDir.childFile('.migrate_manifest');
|
||||
manifestFile.createSync(recursive: true);
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
- pubspec.yaml
|
||||
conflict_files:
|
||||
added_files:
|
||||
- added.file
|
||||
deleted_files:
|
||||
''');
|
||||
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'status',
|
||||
'--staging-directory=${stagingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
|
||||
expect(logger.statusText, contains('''
|
||||
Newly added file at added.file:
|
||||
|
||||
new file contents'''));
|
||||
expect(logger.statusText, contains(r'''
|
||||
Added files:
|
||||
- added.file
|
||||
Modified files:
|
||||
- pubspec.yaml
|
||||
|
||||
All conflicts resolved. Review changes above and apply the migration with:
|
||||
|
||||
$ flutter migrate apply
|
||||
'''));
|
||||
|
||||
expect(logger.statusText, contains(r'''
|
||||
@@ -1,5 +1,5 @@
|
||||
-name: originalname
|
||||
-description: A new Flutter project.
|
||||
+name: newname
|
||||
+description: new description of the test project
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: '>=2.18.0-58.0.dev <3.0.0'
|
||||
@@ -10,4 +10,5 @@ dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
- uses-material-design: true
|
||||
\ No newline at end of file
|
||||
+ uses-material-design: false
|
||||
+ EXTRALINE'''));
|
||||
|
||||
// Add conflict file
|
||||
final File conflictFile = stagingDir.childDirectory('conflict').childFile('conflict.file');
|
||||
conflictFile.createSync(recursive: true);
|
||||
conflictFile.writeAsStringSync('''
|
||||
line1
|
||||
<<<<<<< /conflcit/conflict.file
|
||||
line2
|
||||
=======
|
||||
linetwo
|
||||
>>>>>>> /var/folders/md/gm0zgfcj07vcsj6jkh_mp_wh00ff02/T/flutter_tools.4Xdep8/generatedTargetTemplatetlN44S/conflict/conflict.file
|
||||
line3
|
||||
''', flush: true);
|
||||
final File conflictFileOriginal = appDir.childDirectory('conflict').childFile('conflict.file');
|
||||
conflictFileOriginal.createSync(recursive: true);
|
||||
conflictFileOriginal.writeAsStringSync('''
|
||||
line1
|
||||
line2
|
||||
line3
|
||||
''', flush: true);
|
||||
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
- pubspec.yaml
|
||||
conflict_files:
|
||||
- conflict/conflict.file
|
||||
added_files:
|
||||
- added.file
|
||||
deleted_files:
|
||||
''');
|
||||
|
||||
logger.clear();
|
||||
await createTestCommandRunner(command).run(
|
||||
<String>[
|
||||
'migrate',
|
||||
'status',
|
||||
'--staging-directory=${stagingDir.path}',
|
||||
'--project-directory=${appDir.path}',
|
||||
]
|
||||
);
|
||||
|
||||
expect(logger.statusText, contains('''
|
||||
@@ -1,3 +1,7 @@
|
||||
line1
|
||||
+<<<<<<< /conflcit/conflict.file
|
||||
line2
|
||||
+=======
|
||||
+linetwo
|
||||
+>>>>>>>'''));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
Platform: () => platform,
|
||||
});
|
||||
}
|
||||
@@ -1,400 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/migrate/migrate_manifest.dart';
|
||||
import 'package:flutter_tools/src/migrate/migrate_result.dart';
|
||||
import 'package:flutter_tools/src/migrate/migrate_utils.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
late File manifestFile;
|
||||
late BufferLogger logger;
|
||||
|
||||
setUpAll(() {
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
logger = BufferLogger.test();
|
||||
manifestFile = fileSystem.file('.migrate_manifest');
|
||||
});
|
||||
|
||||
group('checkAndPrintMigrateStatus', () {
|
||||
testWithoutContext('empty MigrateResult produces empty output', () async {
|
||||
final Directory workingDir = fileSystem.directory('migrate_working_dir');
|
||||
workingDir.createSync(recursive: true);
|
||||
final MigrateManifest manifest = MigrateManifest(migrateRootDir: workingDir, migrateResult: MigrateResult(
|
||||
mergeResults: <MergeResult>[],
|
||||
addedFiles: <FilePendingMigration>[],
|
||||
deletedFiles: <FilePendingMigration>[],
|
||||
mergeTypeMap: <String, MergeType>{},
|
||||
diffMap: <String, DiffResult>{},
|
||||
tempDirectories: <Directory>[],
|
||||
sdkDirs: <String, Directory>{},
|
||||
));
|
||||
|
||||
checkAndPrintMigrateStatus(manifest, workingDir, warnConflict: true, logger: logger);
|
||||
|
||||
expect(logger.statusText, contains('\n'));
|
||||
});
|
||||
|
||||
testWithoutContext('populated MigrateResult produces correct output', () async {
|
||||
final Directory workingDir = fileSystem.directory('migrate_working_dir');
|
||||
workingDir.createSync(recursive: true);
|
||||
final MigrateManifest manifest = MigrateManifest(migrateRootDir: workingDir, migrateResult: MigrateResult(
|
||||
mergeResults: <MergeResult>[
|
||||
StringMergeResult.explicit(
|
||||
localPath: 'merged_file',
|
||||
mergedString: 'str',
|
||||
hasConflict: false,
|
||||
exitCode: 0,
|
||||
),
|
||||
StringMergeResult.explicit(
|
||||
localPath: 'conflict_file',
|
||||
mergedString: 'hello\nwow a bunch of lines\n<<<<<<<\n=======\n<<<<<<<\nhi\n',
|
||||
hasConflict: true,
|
||||
exitCode: 1,
|
||||
),
|
||||
],
|
||||
addedFiles: <FilePendingMigration>[FilePendingMigration('added_file', fileSystem.file('added_file'))],
|
||||
deletedFiles: <FilePendingMigration>[FilePendingMigration('deleted_file', fileSystem.file('deleted_file'))],
|
||||
// The following are ignored by the manifest.
|
||||
mergeTypeMap: <String, MergeType>{'test': MergeType.threeWay},
|
||||
diffMap: <String, DiffResult>{},
|
||||
tempDirectories: <Directory>[],
|
||||
sdkDirs: <String, Directory>{},
|
||||
));
|
||||
|
||||
final File conflictFile = workingDir.childFile('conflict_file');
|
||||
conflictFile.writeAsStringSync('hello\nwow a bunch of lines\n<<<<<<<\n=======\n<<<<<<<\nhi\n', flush: true);
|
||||
|
||||
checkAndPrintMigrateStatus(manifest, workingDir, warnConflict: true, logger: logger);
|
||||
|
||||
expect(logger.statusText, contains('''
|
||||
Added files:
|
||||
- added_file
|
||||
Deleted files:
|
||||
- deleted_file
|
||||
Modified files:
|
||||
- conflict_file
|
||||
- merged_file
|
||||
'''));
|
||||
});
|
||||
|
||||
testWithoutContext('populated MigrateResult detects fixed conflict', () async {
|
||||
final Directory workingDir = fileSystem.directory('migrate_working_dir');
|
||||
workingDir.createSync(recursive: true);
|
||||
final MigrateManifest manifest = MigrateManifest(migrateRootDir: workingDir, migrateResult: MigrateResult(
|
||||
mergeResults: <MergeResult>[
|
||||
StringMergeResult.explicit(
|
||||
localPath: 'merged_file',
|
||||
mergedString: 'str',
|
||||
hasConflict: false,
|
||||
exitCode: 0,
|
||||
),
|
||||
StringMergeResult.explicit(
|
||||
localPath: 'conflict_file',
|
||||
mergedString: 'hello\nwow a bunch of lines\n<<<<<<<\n=======\n<<<<<<<\nhi\n',
|
||||
hasConflict: true,
|
||||
exitCode: 1,
|
||||
),
|
||||
],
|
||||
addedFiles: <FilePendingMigration>[FilePendingMigration('added_file', fileSystem.file('added_file'))],
|
||||
deletedFiles: <FilePendingMigration>[FilePendingMigration('deleted_file', fileSystem.file('deleted_file'))],
|
||||
// The following are ignored by the manifest.
|
||||
mergeTypeMap: <String, MergeType>{'test': MergeType.threeWay},
|
||||
diffMap: <String, DiffResult>{},
|
||||
tempDirectories: <Directory>[],
|
||||
sdkDirs: <String, Directory>{},
|
||||
));
|
||||
|
||||
final File conflictFile = workingDir.childFile('conflict_file');
|
||||
conflictFile.writeAsStringSync('hello\nwow a bunch of lines\nhi\n', flush: true);
|
||||
|
||||
checkAndPrintMigrateStatus(manifest, workingDir, warnConflict: true, logger: logger);
|
||||
expect(logger.statusText, contains('''
|
||||
Added files:
|
||||
- added_file
|
||||
Deleted files:
|
||||
- deleted_file
|
||||
Modified files:
|
||||
- conflict_file
|
||||
- merged_file
|
||||
'''));
|
||||
});
|
||||
});
|
||||
|
||||
group('manifest file parsing', () {
|
||||
testWithoutContext('empty fails', () async {
|
||||
manifestFile.writeAsStringSync('');
|
||||
bool exceptionFound = false;
|
||||
try {
|
||||
MigrateManifest.fromFile(manifestFile);
|
||||
} on Exception catch (e) {
|
||||
exceptionFound = true;
|
||||
expect(e.toString(), 'Exception: Invalid .migrate_manifest file in the migrate working directory. File is not a Yaml map.');
|
||||
}
|
||||
expect(exceptionFound, true);
|
||||
});
|
||||
|
||||
testWithoutContext('invalid name fails', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
conflict_files:
|
||||
added_filessssss:
|
||||
deleted_files:
|
||||
''');
|
||||
bool exceptionFound = false;
|
||||
try {
|
||||
MigrateManifest.fromFile(manifestFile);
|
||||
} on Exception catch (e) {
|
||||
exceptionFound = true;
|
||||
expect(e.toString(), 'Exception: Invalid .migrate_manifest file in the migrate working directory. File is missing an entry.');
|
||||
}
|
||||
expect(exceptionFound, true);
|
||||
});
|
||||
|
||||
testWithoutContext('missing name fails', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
conflict_files:
|
||||
deleted_files:
|
||||
''');
|
||||
bool exceptionFound = false;
|
||||
try {
|
||||
MigrateManifest.fromFile(manifestFile);
|
||||
} on Exception catch (e) {
|
||||
exceptionFound = true;
|
||||
expect(e.toString(), 'Exception: Invalid .migrate_manifest file in the migrate working directory. File is missing an entry.');
|
||||
}
|
||||
expect(exceptionFound, true);
|
||||
});
|
||||
|
||||
testWithoutContext('wrong entry type fails', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
conflict_files:
|
||||
other_key:
|
||||
added_files:
|
||||
deleted_files:
|
||||
''');
|
||||
bool exceptionFound = false;
|
||||
try {
|
||||
MigrateManifest.fromFile(manifestFile);
|
||||
} on Exception catch (e) {
|
||||
exceptionFound = true;
|
||||
expect(e.toString(), 'Exception: Invalid .migrate_manifest file in the migrate working directory. Entry is not a Yaml list.');
|
||||
}
|
||||
expect(exceptionFound, true);
|
||||
});
|
||||
|
||||
testWithoutContext('unpopulated succeeds', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
conflict_files:
|
||||
added_files:
|
||||
deleted_files:
|
||||
''');
|
||||
final MigrateManifest manifest = MigrateManifest.fromFile(manifestFile);
|
||||
expect(manifest.mergedFiles.isEmpty, true);
|
||||
expect(manifest.conflictFiles.isEmpty, true);
|
||||
expect(manifest.addedFiles.isEmpty, true);
|
||||
expect(manifest.deletedFiles.isEmpty, true);
|
||||
});
|
||||
|
||||
testWithoutContext('order does not matter', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
added_files:
|
||||
merged_files:
|
||||
deleted_files:
|
||||
conflict_files:
|
||||
''');
|
||||
final MigrateManifest manifest = MigrateManifest.fromFile(manifestFile);
|
||||
expect(manifest.mergedFiles.isEmpty, true);
|
||||
expect(manifest.conflictFiles.isEmpty, true);
|
||||
expect(manifest.addedFiles.isEmpty, true);
|
||||
expect(manifest.deletedFiles.isEmpty, true);
|
||||
});
|
||||
|
||||
testWithoutContext('basic succeeds', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
- file1
|
||||
conflict_files:
|
||||
- file2
|
||||
added_files:
|
||||
- file3
|
||||
deleted_files:
|
||||
- file4
|
||||
''');
|
||||
final MigrateManifest manifest = MigrateManifest.fromFile(manifestFile);
|
||||
expect(manifest.mergedFiles.isEmpty, false);
|
||||
expect(manifest.conflictFiles.isEmpty, false);
|
||||
expect(manifest.addedFiles.isEmpty, false);
|
||||
expect(manifest.deletedFiles.isEmpty, false);
|
||||
|
||||
expect(manifest.mergedFiles.length, 1);
|
||||
expect(manifest.conflictFiles.length, 1);
|
||||
expect(manifest.addedFiles.length, 1);
|
||||
expect(manifest.deletedFiles.length, 1);
|
||||
|
||||
expect(manifest.mergedFiles[0], 'file1');
|
||||
expect(manifest.conflictFiles[0], 'file2');
|
||||
expect(manifest.addedFiles[0], 'file3');
|
||||
expect(manifest.deletedFiles[0], 'file4');
|
||||
});
|
||||
|
||||
testWithoutContext('basic multi-list succeeds', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
- file1
|
||||
- file2
|
||||
conflict_files:
|
||||
added_files:
|
||||
deleted_files:
|
||||
- file3
|
||||
- file4
|
||||
''');
|
||||
final MigrateManifest manifest = MigrateManifest.fromFile(manifestFile);
|
||||
expect(manifest.mergedFiles.isEmpty, false);
|
||||
expect(manifest.conflictFiles.isEmpty, true);
|
||||
expect(manifest.addedFiles.isEmpty, true);
|
||||
expect(manifest.deletedFiles.isEmpty, false);
|
||||
|
||||
expect(manifest.mergedFiles.length, 2);
|
||||
expect(manifest.conflictFiles.length, 0);
|
||||
expect(manifest.addedFiles.length, 0);
|
||||
expect(manifest.deletedFiles.length, 2);
|
||||
|
||||
expect(manifest.mergedFiles[0], 'file1');
|
||||
expect(manifest.mergedFiles[1], 'file2');
|
||||
expect(manifest.deletedFiles[0], 'file3');
|
||||
expect(manifest.deletedFiles[1], 'file4');
|
||||
});
|
||||
});
|
||||
|
||||
group('manifest MigrateResult creation', () {
|
||||
testWithoutContext('empty MigrateResult', () async {
|
||||
final MigrateManifest manifest = MigrateManifest(migrateRootDir: fileSystem.directory('root'), migrateResult: MigrateResult(
|
||||
mergeResults: <MergeResult>[],
|
||||
addedFiles: <FilePendingMigration>[],
|
||||
deletedFiles: <FilePendingMigration>[],
|
||||
mergeTypeMap: <String, MergeType>{},
|
||||
diffMap: <String, DiffResult>{},
|
||||
tempDirectories: <Directory>[],
|
||||
sdkDirs: <String, Directory>{},
|
||||
));
|
||||
expect(manifest.mergedFiles.isEmpty, true);
|
||||
expect(manifest.conflictFiles.isEmpty, true);
|
||||
expect(manifest.addedFiles.isEmpty, true);
|
||||
expect(manifest.deletedFiles.isEmpty, true);
|
||||
});
|
||||
|
||||
testWithoutContext('simple MigrateResult', () async {
|
||||
final MigrateManifest manifest = MigrateManifest(migrateRootDir: fileSystem.directory('root'), migrateResult: MigrateResult(
|
||||
mergeResults: <MergeResult>[
|
||||
StringMergeResult.explicit(
|
||||
localPath: 'merged_file',
|
||||
mergedString: 'str',
|
||||
hasConflict: false,
|
||||
exitCode: 0,
|
||||
),
|
||||
StringMergeResult.explicit(
|
||||
localPath: 'conflict_file',
|
||||
mergedString: '<<<<<<<<<<<',
|
||||
hasConflict: true,
|
||||
exitCode: 1,
|
||||
),
|
||||
],
|
||||
addedFiles: <FilePendingMigration>[FilePendingMigration('added_file', fileSystem.file('added_file'))],
|
||||
deletedFiles: <FilePendingMigration>[FilePendingMigration('deleted_file', fileSystem.file('deleted_file'))],
|
||||
// The following are ignored by the manifest.
|
||||
mergeTypeMap: <String, MergeType>{'test': MergeType.threeWay},
|
||||
diffMap: <String, DiffResult>{},
|
||||
tempDirectories: <Directory>[],
|
||||
sdkDirs: <String, Directory>{},
|
||||
));
|
||||
expect(manifest.mergedFiles.isEmpty, false);
|
||||
expect(manifest.conflictFiles.isEmpty, false);
|
||||
expect(manifest.addedFiles.isEmpty, false);
|
||||
expect(manifest.deletedFiles.isEmpty, false);
|
||||
|
||||
expect(manifest.mergedFiles.length, 1);
|
||||
expect(manifest.conflictFiles.length, 1);
|
||||
expect(manifest.addedFiles.length, 1);
|
||||
expect(manifest.deletedFiles.length, 1);
|
||||
|
||||
expect(manifest.mergedFiles[0], 'merged_file');
|
||||
expect(manifest.conflictFiles[0], 'conflict_file');
|
||||
expect(manifest.addedFiles[0], 'added_file');
|
||||
expect(manifest.deletedFiles[0], 'deleted_file');
|
||||
});
|
||||
});
|
||||
|
||||
group('manifest write', () {
|
||||
testWithoutContext('empty', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
conflict_files:
|
||||
added_files:
|
||||
deleted_files:
|
||||
''');
|
||||
final MigrateManifest manifest = MigrateManifest.fromFile(manifestFile);
|
||||
expect(manifest.mergedFiles.isEmpty, true);
|
||||
expect(manifest.conflictFiles.isEmpty, true);
|
||||
expect(manifest.addedFiles.isEmpty, true);
|
||||
expect(manifest.deletedFiles.isEmpty, true);
|
||||
|
||||
manifest.writeFile();
|
||||
expect(manifestFile.readAsStringSync(), '''
|
||||
merged_files:
|
||||
conflict_files:
|
||||
added_files:
|
||||
deleted_files:
|
||||
''');
|
||||
});
|
||||
|
||||
testWithoutContext('basic multi-list', () async {
|
||||
manifestFile.writeAsStringSync('''
|
||||
merged_files:
|
||||
- file1
|
||||
- file2
|
||||
conflict_files:
|
||||
added_files:
|
||||
deleted_files:
|
||||
- file3
|
||||
- file4
|
||||
''');
|
||||
final MigrateManifest manifest = MigrateManifest.fromFile(manifestFile);
|
||||
expect(manifest.mergedFiles.isEmpty, false);
|
||||
expect(manifest.conflictFiles.isEmpty, true);
|
||||
expect(manifest.addedFiles.isEmpty, true);
|
||||
expect(manifest.deletedFiles.isEmpty, false);
|
||||
|
||||
expect(manifest.mergedFiles.length, 2);
|
||||
expect(manifest.conflictFiles.length, 0);
|
||||
expect(manifest.addedFiles.length, 0);
|
||||
expect(manifest.deletedFiles.length, 2);
|
||||
|
||||
expect(manifest.mergedFiles[0], 'file1');
|
||||
expect(manifest.mergedFiles[1], 'file2');
|
||||
expect(manifest.deletedFiles[0], 'file3');
|
||||
expect(manifest.deletedFiles[1], 'file4');
|
||||
|
||||
manifest.writeFile();
|
||||
expect(manifestFile.readAsStringSync(), '''
|
||||
merged_files:
|
||||
- file1
|
||||
- file2
|
||||
conflict_files:
|
||||
added_files:
|
||||
deleted_files:
|
||||
- file3
|
||||
- file4
|
||||
''');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/process.dart';
|
||||
import 'package:flutter_tools/src/commands/migrate.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/migrate/migrate_utils.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
|
||||
void main() {
|
||||
late BufferLogger logger;
|
||||
late FileSystem fileSystem;
|
||||
late Directory projectRoot;
|
||||
late String projectRootPath;
|
||||
late ProcessUtils processUtils;
|
||||
late MigrateUtils utils;
|
||||
|
||||
setUpAll(() async {
|
||||
fileSystem = globals.localFileSystem;
|
||||
logger = BufferLogger.test();
|
||||
utils = MigrateUtils(
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
platform: globals.platform,
|
||||
processManager: globals.processManager,
|
||||
);
|
||||
processUtils = ProcessUtils(processManager: globals.processManager, logger: logger);
|
||||
});
|
||||
|
||||
group('git', () {
|
||||
setUp(() async {
|
||||
projectRoot = fileSystem.systemTempDirectory.createTempSync('flutter_migrate_command_test');
|
||||
projectRoot.createSync(recursive: true);
|
||||
projectRootPath = projectRoot.path;
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(projectRoot);
|
||||
});
|
||||
|
||||
testWithoutContext('isGitRepo', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
|
||||
expect(await gitRepoExists(projectRootPath, logger, utils), false);
|
||||
expect(logger.statusText, contains('Project is not a git repo. Please initialize a git repo and try again.'));
|
||||
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
expect(await gitRepoExists(projectRootPath, logger, utils), true);
|
||||
});
|
||||
|
||||
testWithoutContext('printCommandText produces formatted output', () async {
|
||||
printCommandText('some command --help', logger);
|
||||
|
||||
expect(logger.statusText, contains(r' $ some command --help'));
|
||||
});
|
||||
|
||||
testWithoutContext('hasUncommittedChanges false on clean repo', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
projectRoot.childFile('.gitignore')
|
||||
..createSync()
|
||||
..writeAsStringSync('ignored_file.dart', flush: true);
|
||||
|
||||
await processUtils.run(<String>['git', 'add', '.'], workingDirectory: projectRootPath);
|
||||
await processUtils.run(<String>['git', 'commit', '-m', 'Initial commit'], workingDirectory: projectRootPath);
|
||||
|
||||
expect(await hasUncommittedChanges(projectRootPath, logger, utils), false);
|
||||
});
|
||||
|
||||
testWithoutContext('hasUncommittedChanges true on dirty repo', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
projectRoot.childFile('some_file.dart')
|
||||
..createSync()
|
||||
..writeAsStringSync('void main() {}', flush: true);
|
||||
|
||||
expect(await hasUncommittedChanges(projectRootPath, logger, utils), true);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/flutter_project_metadata.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import 'test_data/migrate_project.dart';
|
||||
import 'test_driver.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
|
||||
void main() {
|
||||
late Directory tempDir;
|
||||
late FlutterRunTestDriver flutter;
|
||||
late Logger logger;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = createResolvedTempDirectorySync('run_test.');
|
||||
flutter = FlutterRunTestDriver(tempDir);
|
||||
logger = BufferLogger.test();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await flutter.stop();
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
testWithoutContext('parse simple config file', () async {
|
||||
final File metadataFile = tempDir.childFile('.metadata');
|
||||
metadataFile.createSync(recursive: true);
|
||||
metadataFile.writeAsStringSync('''
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled.
|
||||
|
||||
version:
|
||||
revision: fj19vkla9vnlka9vni3n808v3nch8cd
|
||||
channel: stable
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: fj19vkla9vnlka9vni3n808v3nch8cd
|
||||
base_revision: 93kf9v3njfa90vnidfjvn39nvi3vnie
|
||||
- platform: android
|
||||
create_revision: abfj19vkla9vnlka9vni3n808v3nch8cd
|
||||
base_revision: ab93kf9v3njfa90vnidfjvn39nvi3vnie
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- lib/main.dart
|
||||
- ios/Runner.xcodeproj/project.pbxproj
|
||||
- lib/file1/etc.dart
|
||||
- android/my_file.java
|
||||
''', flush: true);
|
||||
FlutterProjectMetadata metadata = FlutterProjectMetadata(metadataFile, logger);
|
||||
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.root]!.createRevision, equals('fj19vkla9vnlka9vni3n808v3nch8cd'));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.root]!.baseRevision, equals('93kf9v3njfa90vnidfjvn39nvi3vnie'));
|
||||
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.android]!.createRevision, equals('abfj19vkla9vnlka9vni3n808v3nch8cd'));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.android]!.baseRevision, equals('ab93kf9v3njfa90vnidfjvn39nvi3vnie'));
|
||||
|
||||
expect(metadata.migrateConfig.unmanagedFiles[0], equals('lib/main.dart'));
|
||||
expect(metadata.migrateConfig.unmanagedFiles[1], equals('ios/Runner.xcodeproj/project.pbxproj'));
|
||||
expect(metadata.migrateConfig.unmanagedFiles[2], equals('lib/file1/etc.dart'));
|
||||
expect(metadata.migrateConfig.unmanagedFiles[3], equals('android/my_file.java'));
|
||||
|
||||
metadataFile.writeAsStringSync('''
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled.
|
||||
|
||||
version:
|
||||
revision: fj19vkla9vnlka9vni3n808v3nch8cd
|
||||
channel: stable
|
||||
|
||||
project_type: app
|
||||
''', flush: true);
|
||||
|
||||
metadata = FlutterProjectMetadata(metadataFile, logger);
|
||||
|
||||
expect(metadata.migrateConfig.isEmpty, equals(true));
|
||||
expect(metadata.versionRevision, equals('fj19vkla9vnlka9vni3n808v3nch8cd'));
|
||||
expect(metadata.versionChannel, equals('stable'));
|
||||
});
|
||||
|
||||
testUsingContext('write simple config file', () async {
|
||||
const String testCreateRevision = 'testmc9skl32nlnf23lnakcs9njr3';
|
||||
const String testBaseRevision = 'testanas9anlnq9ba7bjhavan3kma';
|
||||
MigrateConfig config = MigrateConfig(
|
||||
platformConfigs: <SupportedPlatform, MigratePlatformConfig>{
|
||||
SupportedPlatform.android: MigratePlatformConfig(platform: SupportedPlatform.android, createRevision: testCreateRevision, baseRevision: testBaseRevision),
|
||||
SupportedPlatform.ios: MigratePlatformConfig(platform: SupportedPlatform.ios, createRevision: testCreateRevision, baseRevision: testBaseRevision),
|
||||
SupportedPlatform.root: MigratePlatformConfig(platform: SupportedPlatform.root, createRevision: testCreateRevision, baseRevision: testBaseRevision),
|
||||
SupportedPlatform.windows: MigratePlatformConfig(platform: SupportedPlatform.windows, createRevision: testCreateRevision, baseRevision: testBaseRevision),
|
||||
},
|
||||
unmanagedFiles: <String>[
|
||||
'lib/main.dart',
|
||||
'ios/Runner.xcodeproj/project.pbxproj',
|
||||
'lib/file1/etc.dart',
|
||||
],
|
||||
);
|
||||
String outputString = config.getOutputFileString();
|
||||
expect(outputString, equals('''
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: android
|
||||
create_revision: $testCreateRevision
|
||||
base_revision: $testBaseRevision
|
||||
- platform: ios
|
||||
create_revision: $testCreateRevision
|
||||
base_revision: $testBaseRevision
|
||||
- platform: root
|
||||
create_revision: $testCreateRevision
|
||||
base_revision: $testBaseRevision
|
||||
- platform: windows
|
||||
create_revision: $testCreateRevision
|
||||
base_revision: $testBaseRevision
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
- 'lib/file1/etc.dart'
|
||||
'''));
|
||||
|
||||
config = MigrateConfig();
|
||||
outputString = config.getOutputFileString();
|
||||
expect(outputString, equals(''));
|
||||
});
|
||||
|
||||
testUsingContext('populate migrate config', () async {
|
||||
// Flutter Stable 1.22.6 hash: 9b2d32b605630f28625709ebd9d78ab3016b2bf6
|
||||
final MigrateProject project = MigrateProject('version:1.22.6_stable');
|
||||
await project.setUpIn(tempDir);
|
||||
|
||||
final File metadataFile = tempDir.childFile('.metadata');
|
||||
|
||||
const String currentRevision = 'test_base_revision';
|
||||
const String createRevision = 'test_create_revision';
|
||||
|
||||
final FlutterProjectMetadata metadata = FlutterProjectMetadata(metadataFile, logger);
|
||||
metadata.migrateConfig.populate(
|
||||
projectDirectory: tempDir,
|
||||
currentRevision: currentRevision,
|
||||
createRevision: createRevision,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(metadata.migrateConfig.platformConfigs.length, equals(3));
|
||||
|
||||
final List<SupportedPlatform> keyList = List<SupportedPlatform>.from(metadata.migrateConfig.platformConfigs.keys);
|
||||
|
||||
expect(keyList[0], equals(SupportedPlatform.root));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.root]!.baseRevision, equals(currentRevision));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.root]!.createRevision, equals(createRevision));
|
||||
|
||||
expect(keyList[1], equals(SupportedPlatform.android));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.android]!.baseRevision, equals(currentRevision));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.android]!.createRevision, equals(createRevision));
|
||||
|
||||
expect(keyList[2], equals(SupportedPlatform.ios));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.ios]!.baseRevision, equals(currentRevision));
|
||||
expect(metadata.migrateConfig.platformConfigs[SupportedPlatform.ios]!.createRevision, equals(createRevision));
|
||||
|
||||
final File metadataFileOutput = tempDir.childFile('.metadata_output');
|
||||
metadata.writeFile(outputFile: metadataFileOutput);
|
||||
expect(metadataFileOutput.readAsStringSync(), equals('''
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled.
|
||||
|
||||
version:
|
||||
revision: 9b2d32b605630f28625709ebd9d78ab3016b2bf6
|
||||
channel: unknown
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: $createRevision
|
||||
base_revision: $currentRevision
|
||||
- platform: android
|
||||
create_revision: $createRevision
|
||||
base_revision: $currentRevision
|
||||
- platform: ios
|
||||
create_revision: $createRevision
|
||||
base_revision: $currentRevision
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
'''));
|
||||
});
|
||||
|
||||
testUsingContext('equality compares platform', () async {
|
||||
const String testCreateRevision = 'testmc9skl32nlnf23lnakcs9njr3';
|
||||
const String testBaseRevision = 'testanas9anlnq9ba7bjhavan3kma';
|
||||
final MigratePlatformConfig configAndroid = MigratePlatformConfig(platform: SupportedPlatform.android, createRevision: testCreateRevision, baseRevision: testBaseRevision);
|
||||
final MigratePlatformConfig configIos = MigratePlatformConfig(platform: SupportedPlatform.ios, createRevision: testCreateRevision, baseRevision: testBaseRevision);
|
||||
|
||||
expect(configAndroid.equals(configIos), false);
|
||||
expect(configAndroid.equals(configAndroid), true);
|
||||
expect(configIos.equals(configIos), true);
|
||||
});
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/process.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/migrate/migrate_utils.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
|
||||
void main() {
|
||||
late BufferLogger logger;
|
||||
late FileSystem fileSystem;
|
||||
late Directory projectRoot;
|
||||
late String projectRootPath;
|
||||
late MigrateUtils utils;
|
||||
late ProcessUtils processUtils;
|
||||
|
||||
setUpAll(() async {
|
||||
fileSystem = globals.localFileSystem;
|
||||
logger = BufferLogger.test();
|
||||
utils = MigrateUtils(
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
platform: globals.platform,
|
||||
processManager: globals.processManager,
|
||||
);
|
||||
processUtils = ProcessUtils(processManager: globals.processManager, logger: logger);
|
||||
});
|
||||
|
||||
group('git', () {
|
||||
setUp(() async {
|
||||
projectRoot = fileSystem.systemTempDirectory.createTempSync('flutter_migrate_utils_test');
|
||||
projectRoot.createSync(recursive: true);
|
||||
projectRootPath = projectRoot.path;
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(projectRoot);
|
||||
});
|
||||
|
||||
testWithoutContext('init', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
});
|
||||
|
||||
testWithoutContext('isGitIgnored', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
projectRoot.childFile('.gitignore')
|
||||
..createSync()
|
||||
..writeAsStringSync('ignored_file.dart', flush: true);
|
||||
|
||||
expect(await utils.isGitIgnored('ignored_file.dart', projectRootPath), true);
|
||||
expect(await utils.isGitIgnored('other_file.dart', projectRootPath), false);
|
||||
});
|
||||
|
||||
testWithoutContext('isGitRepo', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
expect(await utils.isGitRepo(projectRootPath), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
expect(await utils.isGitRepo(projectRootPath), true);
|
||||
|
||||
expect(await utils.isGitRepo(projectRoot.parent.path), false);
|
||||
});
|
||||
|
||||
testWithoutContext('hasUncommittedChanges false on clean repo', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
projectRoot.childFile('.gitignore')
|
||||
..createSync()
|
||||
..writeAsStringSync('ignored_file.dart', flush: true);
|
||||
|
||||
await processUtils.run(<String>['git', 'add', '.'], workingDirectory: projectRootPath);
|
||||
await processUtils.run(<String>['git', 'commit', '-m', 'Initial commit'], workingDirectory: projectRootPath);
|
||||
|
||||
expect(await utils.hasUncommittedChanges(projectRootPath), false);
|
||||
});
|
||||
|
||||
testWithoutContext('hasUncommittedChanges true on dirty repo', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
projectRoot.childFile('some_file.dart')
|
||||
..createSync()
|
||||
..writeAsStringSync('void main() {}', flush: true);
|
||||
|
||||
expect(await utils.hasUncommittedChanges(projectRootPath), true);
|
||||
});
|
||||
|
||||
testWithoutContext('diffFiles', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
final File file1 = projectRoot.childFile('some_file.dart')
|
||||
..createSync()
|
||||
..writeAsStringSync('void main() {}\n', flush: true);
|
||||
|
||||
final File file2 = projectRoot.childFile('some_other_file.dart');
|
||||
|
||||
DiffResult result = await utils.diffFiles(file1, file2);
|
||||
expect(result.diff, null);
|
||||
expect(result.diffType, DiffType.deletion);
|
||||
expect(result.exitCode, null);
|
||||
|
||||
result = await utils.diffFiles(file2, file1);
|
||||
expect(result.diff, null);
|
||||
expect(result.diffType, DiffType.addition);
|
||||
expect(result.exitCode, null);
|
||||
|
||||
file2.createSync();
|
||||
file2.writeAsStringSync('void main() {}\n', flush: true);
|
||||
|
||||
result = await utils.diffFiles(file1, file2);
|
||||
expect(result.diff, '');
|
||||
expect(result.diffType, DiffType.command);
|
||||
expect(result.exitCode, 0);
|
||||
|
||||
file2.writeAsStringSync('void main() {}\na second line\na third line\n', flush: true);
|
||||
|
||||
result = await utils.diffFiles(file1, file2);
|
||||
expect(result.diff, contains('@@ -1 +1,3 @@\n void main() {}\n+a second line\n+a third line'));
|
||||
expect(result.diffType, DiffType.command);
|
||||
expect(result.exitCode, 1);
|
||||
});
|
||||
|
||||
testWithoutContext('merge', () async {
|
||||
expect(projectRoot.existsSync(), true);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), false);
|
||||
await utils.gitInit(projectRootPath);
|
||||
expect(projectRoot.childDirectory('.git').existsSync(), true);
|
||||
|
||||
final File file1 = projectRoot.childFile('some_file.dart');
|
||||
file1.createSync();
|
||||
file1.writeAsStringSync('void main() {}\n\nline1\nline2\nline3\nline4\nline5\n', flush: true);
|
||||
final File file2 = projectRoot.childFile('some_other_file.dart');
|
||||
file2.createSync();
|
||||
file2.writeAsStringSync('void main() {}\n\nline1\nline2\nline3.0\nline3.5\nline4\nline5\n', flush: true);
|
||||
final File file3 = projectRoot.childFile('some_other_third_file.dart');
|
||||
file3.createSync();
|
||||
file3.writeAsStringSync('void main() {}\n\nline2\nline3\nline4\nline5\n', flush: true);
|
||||
|
||||
StringMergeResult result = await utils.gitMergeFile(
|
||||
base: file1.path,
|
||||
current: file2.path,
|
||||
target: file3.path,
|
||||
localPath: 'some_file.dart',
|
||||
) as StringMergeResult;
|
||||
|
||||
expect(result.mergedString, 'void main() {}\n\nline2\nline3.0\nline3.5\nline4\nline5\n');
|
||||
expect(result.hasConflict, false);
|
||||
expect(result.exitCode, 0);
|
||||
|
||||
file3.writeAsStringSync('void main() {}\n\nline1\nline2\nline3.1\nline3.5\nline4\nline5\n', flush: true);
|
||||
|
||||
result = await utils.gitMergeFile(
|
||||
base: file1.path,
|
||||
current: file2.path,
|
||||
target: file3.path,
|
||||
localPath: 'some_file.dart',
|
||||
) as StringMergeResult;
|
||||
|
||||
expect(result.mergedString, contains('line3.0\n=======\nline3.1\n>>>>>>>'));
|
||||
expect(result.hasConflict, true);
|
||||
expect(result.exitCode, 1);
|
||||
|
||||
// Two way merge
|
||||
result = await utils.gitMergeFile(
|
||||
base: file1.path,
|
||||
current: file1.path,
|
||||
target: file3.path,
|
||||
localPath: 'some_file.dart',
|
||||
) as StringMergeResult;
|
||||
|
||||
expect(result.mergedString, 'void main() {}\n\nline1\nline2\nline3.1\nline3.5\nline4\nline5\n');
|
||||
expect(result.hasConflict, false);
|
||||
expect(result.exitCode, 0);
|
||||
});
|
||||
});
|
||||
|
||||
group('legacy app creation', () {
|
||||
testWithoutContext('clone and create', () async {
|
||||
projectRoot = fileSystem.systemTempDirectory.createTempSync('flutter_sdk_test');
|
||||
const String revision = '5391447fae6209bb21a89e6a5a6583cac1af9b4b';
|
||||
|
||||
expect(await utils.cloneFlutter(revision, projectRoot.path), true);
|
||||
expect(projectRoot.childFile('README.md').existsSync(), true);
|
||||
|
||||
final Directory appDir = fileSystem.systemTempDirectory.createTempSync('flutter_app');
|
||||
await utils.createFromTemplates(
|
||||
projectRoot.childDirectory('bin').path,
|
||||
name: 'testapp',
|
||||
androidLanguage: 'java',
|
||||
iosLanguage: 'objc',
|
||||
outputDirectory: appDir.path,
|
||||
);
|
||||
expect(appDir.childFile('pubspec.yaml').existsSync(), true);
|
||||
expect(appDir.childFile('.metadata').existsSync(), true);
|
||||
expect(appDir.childFile('.metadata').readAsStringSync(), contains(revision));
|
||||
expect(appDir.childDirectory('android').existsSync(), true);
|
||||
expect(appDir.childDirectory('ios').existsSync(), true);
|
||||
expect(appDir.childDirectory('web').existsSync(), false);
|
||||
|
||||
projectRoot.deleteSync(recursive: true);
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('conflictsResolved', () async {
|
||||
expect(utils.conflictsResolved(''), true);
|
||||
expect(utils.conflictsResolved('hello'), true);
|
||||
expect(utils.conflictsResolved('hello\n'), true);
|
||||
expect(utils.conflictsResolved('hello\nwow a bunch of lines\n\nhi\n'), true);
|
||||
expect(utils.conflictsResolved('hello\nwow a bunch of lines\n>>>>>>>\nhi\n'), false);
|
||||
expect(utils.conflictsResolved('hello\nwow a bunch of lines\n=======\nhi\n'), false);
|
||||
expect(utils.conflictsResolved('hello\nwow a bunch of lines\n<<<<<<<\nhi\n'), false);
|
||||
expect(utils.conflictsResolved('hello\nwow a bunch of lines\n<<<<<<<\n=======\n<<<<<<<\nhi\n'), false);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user