Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate status #102785

Merged
merged 18 commits into from
Jun 3, 2022
Merged

Migrate status #102785

merged 18 commits into from
Jun 3, 2022

Conversation

GaryQian
Copy link
Contributor

@GaryQian GaryQian commented Apr 28, 2022

flutter migrate status subcommand.

This command shows the diffs staged in the migrate working directory and the manifest of files to be changed.

Depends on #101937

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 28, 2022
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Directory workingDirectory = project.directory.childDirectory(kDefaultMigrateWorkingDirectoryName);
final String? customWorkingDirectoryPath = stringArg('working-directory');
if (customWorkingDirectoryPath != null) {
if (customWorkingDirectoryPath.startsWith(fileSystem.path.separator) || customWorkingDirectoryPath.startsWith('/')) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work on Windows?

'working-directory',
help: 'Specifies the custom migration working directory used to stage and edit proposed changes. '
'This path can be absolute or relative to the flutter project root.',
valueHelp: 'path',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it mention the default directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ill add it in the help text!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk if this will be painful, but can we name this something else, maybe workspace-directory? I think this will be confusing with the current working directory of the tool invocation. In reading the code, I thought this field was a way to override the project directory.

Copy link
Contributor Author

@GaryQian GaryQian Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to migrate_staging_dir and the parameter to staging-directory

help: 'Shows the diff output when enabled. Enabled by default.',
);
argParser.addFlag(
'show-added-files',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the use case for this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of these flags assist in spam-reduction to make it easier to find the diffs/info the user is actually looking for.

valueHelp: 'path',
);
argParser.addFlag(
'diff',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the use case for disabling this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diffs can often be quite spammy, programmatic uses especially may not wish to have such an extensive output.

);
argParser.addOption(
'project-directory',
help: 'The root directory of the flutter project.',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for simplicity, should it only assume the current directory is the project directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tool is also intended to be used programmatically, where this option helps immensely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like if this is not provided we default to the current working directory, can we document this?

Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{};

/// Manually marks the lines in a diff that should be printed unformatted for visbility.
final Set<int> _initialDiffLines = <int>{0, 1};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do these lines contain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines just include the file names being diffed for example:

diff --git a/Users/garyq/projects/vanillabase1226/android/app/src/main/res/values/styles.xml b/Users/garyq/projects/vanillabase1226/migrate_working_dir/android/app/src/main/res/values/styles.xml
index 1f83a33..8dbda4a 100644

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you flesh out the dartdoc with this example?

int lineNumber = -1;
for (final String line in result.diff!.split('\n')) {
lineNumber++;
if (line.startsWith('---') || line.startsWith('+++') || line.startsWith('&&') || _initialDiffLines.contains(lineNumber)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if a line starts with ---, +++, && in the original file?

Copy link
Contributor Author

@GaryQian GaryQian May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first character of the line is reserved for the + and - character, so lines that start with those strings in the original files would appear as _--- _+++ and _&& where underscore is a space. The initial space character would cause the startsWith check to fail.

required this.logger,
// TODO(garyq): Add each parameters in as subcommands land.
// TODO(garyq): Add each of these back in as they land.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add in what?

Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{};

/// Manually marks the lines in a diff that should be printed unformatted for visbility.
final Set<int> _initialDiffLines = <int>{0, 1};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you flesh out the dartdoc with this example?

'working-directory',
help: 'Specifies the custom migration working directory used to stage and edit proposed changes. '
'This path can be absolute or relative to the flutter project root.',
valueHelp: 'path',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk if this will be painful, but can we name this something else, maybe workspace-directory? I think this will be confusing with the current working directory of the tool invocation. In reading the code, I thought this field was a way to override the project directory.

);
argParser.addOption(
'project-directory',
help: 'The root directory of the flutter project.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like if this is not provided we default to the current working directory, can we document this?

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// import 'package:flutter_tools/src/base/terminal.dart';

@@ -0,0 +1,202 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this file to packages/flutter_tools/test/command.shard/permeable/migrate_status_test.dart?

]
);
expect(logger.statusText, contains('''
Newly addded file at added.file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling?

deleted_files:
''');

expect(appDir.childFile('lib/main.dart').existsSync(), true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed? we explicitly created it on line 55, are we testing it didn't get deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, this is leftover from another test this was based on. I can remove.

conflictFile.createSync(recursive: true);
conflictFile.writeAsStringSync('''
line1
<<<<<<< /conflcit/conflict.file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling?

expect(logger.statusText, contains('''
@@ -1,3 +1,7 @@
line1
+<<<<<<< /conflcit/conflict.file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling?

@GaryQian
Copy link
Contributor Author

Ready for another round. Thanks! @christopherfujino

Directory workingDirectory = project.directory.childDirectory(kDefaultMigrateWorkingDirectoryName);
final String? customWorkingDirectoryPath = stringArg('working-directory');
if (customWorkingDirectoryPath != null) {
if (customWorkingDirectoryPath.startsWith(fileSystem.path.separator) || customWorkingDirectoryPath.startsWith(RegExp(r'[A-Z]:\\'))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get a path context from the filesystem and use https://pub.dev/documentation/path/latest/path/isAbsolute.html instead of re-implementing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, already did it, just needed to sync it with the other PRs

@GaryQian GaryQian requested a review from zanderso June 1, 2022 19:43
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 6, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants