Repository navigation
[flutter_tools] Make flutter upgrade only work with standard remotes - #79372
Conversation
flutter_upgrade to only work with standard remotes.flutter_upgrade only work with standard remotes.
flutter_upgrade only work with standard remotes.flutter upgrade only work with standard remotes
|
Might be able to close #49713 as well. I mean I don't know why that happened, but it would have failed earlier... |
|
This PR could fix multiple open issues relating to As the error message is depending on Having to flutter/packages/flutter_tools/lib/src/commands/upgrade.dart Lines 247 to 252 in 8158b47 flutter/packages/flutter_tools/lib/src/commands/upgrade.dart Lines 254 to 257 in 8158b47 flutterVersion.repositoryUrl will always provide null values in either case.
The possible solution is to include this message in flutter/packages/flutter_tools/lib/src/commands/upgrade.dart Lines 228 to 263 in 8158b47 Somewhere after line 261. This can be summarized as: But this has a caveat: it still fetches from the upstream, whether supported or not, which in my opinion is completely unnecessary. We could make it to fetch tags only if we determine that the upstream is supported: But this will fetch after the HEAD of the upstream is obtained, in the case the upstream is properly configured. Additionally, making this error message dependent on |
christopherfujino
left a comment
There was a problem hiding this comment.
This looks like a good change! Two changes requested.
There was a problem hiding this comment.
Can we consolidate this getter and the one in //flutter_tools/lib/src/version.dart by moving them both into //flutter_tools/lib/src/globals.dart, where it would look something like this:
String get flutterGit => platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
There was a problem hiding this comment.
It would be better to make this change in a different PR after this one lands.
Opened #79568.
So we're getting |
Isn't this covered by flutter/packages/flutter_tools/lib/src/commands/upgrade.dart Lines 247 to 252 in 8158b47 we just need to add some lines addressing detached HEAD state. |
|
I've decided to go with the first approach of #79372 (comment)
Fetching the unsupported remote is something I'm OK to live with. |
Doesn't that check happen after the new one you added in this PR? |
|
@christopherfujino I would suggest you to not review this PR for now (I've marked it as draft). I'm currently in the process of writing tests for a different version of this PR. Will ping you to review when I'm done with testing on my end and satisfied with its state. |
flutter upgrade only work with standard remotesflutter upgrade only work with standard remotes
There was a problem hiding this comment.
I'm not sure this error message was accurately being displayed if the user was not on a release branch (branches other than kOfficialChannels). I changed this to only warn about detached HEAD states.
There was a problem hiding this comment.
If the user is on a detached HEAD, they would also not be on a release branch right? Even if this message is more specific, I doubt most casual git users understand what a detached HEAD state is, when what is relevant to their use of Flutter is that they are not on an official channel. What do you think?
There was a problem hiding this comment.
Also, while we're at it, we can advise the user to use flutter channel stable, rather than doing a git checkout directly.
flutter upgrade only work with standard remotesflutter upgrade only work with standard remotes
|
Hi @christopherfujino, PR is ready for review. |
c89a156 to
d6c0ec1
Compare
christopherfujino
left a comment
There was a problem hiding this comment.
The code here looks good. I just have some requested changes for exact messaging we communicate to the user, and a few points I wasn't sure on.
Overall, I really appreciate you contributing to this part of the codebase, as you know it is confusing and rife with edge cases. Overall, we're trying to nudge users away from directly manipulating their git repositories via the CLI, because if they get into a weird state they will file a bug, and it will be difficult for us to diagnose. And if they're a power user, they'll disregard our recommendations and hopefully they will be able to get their repo back into a good state.
There was a problem hiding this comment.
rather than listing them out, can you refer the reader to look up the _flutterGit getter, in case we ever change that function but forget to update the comment.
There was a problem hiding this comment.
Although the details here are true, they may change later. You can future-proof this comment by merely saying "Using flutter upgrade is not supported from a non-standard remote."
There was a problem hiding this comment.
Can you rename this verifyStandardRemote()? When I read check I think that it's going to return a value, rather than potentially exit.
There was a problem hiding this comment.
From experience, I try to avoid suggesting git commands to users via the CLI tool. There are many ways for a user to accidentally misconfigure their repo if they're not familiar with git, and these become very difficult to decipher issues.
Instead, can you refer the user to this page on the website to re-install Flutter: https://flutter.dev/docs/get-started/install
There was a problem hiding this comment.
Should I include this link to the toolExit message for detached HEAD and missing upstream as well?
There was a problem hiding this comment.
Yes, that sounds good!
There was a problem hiding this comment.
| Future<FlutterVersion> fetchLatestVersion({@required FlutterVersion localVersion}) async { | |
| Future<FlutterVersion> fetchLatestVersion({ | |
| @required FlutterVersion localVersion, | |
| }) async { |
There was a problem hiding this comment.
If the user is on a detached HEAD, they would also not be on a release branch right? Even if this message is more specific, I doubt most casual git users understand what a detached HEAD state is, when what is relevant to their use of Flutter is that they are not on an official channel. What do you think?
There was a problem hiding this comment.
Also, while we're at it, we can advise the user to use flutter channel stable, rather than doing a git checkout directly.
There was a problem hiding this comment.
note that this method could return '[user-branch]'
There was a problem hiding this comment.
this could also throw if they're in a detached head state, but tool exiting with the message "fatal: HEAD does not point to a branch" will probably be more confusing than the original tool exit message.
There was a problem hiding this comment.
This toolExit won't show for detached HEAD states. The toolExit above takes care of that. This is only if the local branch isn't tracking anything(Similar to the use case of #79366).
There was a problem hiding this comment.
ahh, yeah, you're right.
There was a problem hiding this comment.
If any user sets the tracking repository as https://github.com/flutter/flutter(no ".git" suffix) and having FLUTTER_GIT_URL unset, this will fail. How do I handle this case?
There was a problem hiding this comment.
Good catch, and that's annoying. You could write a utility function and pass both localVersion.repositoryUrl and _flutterGit through it before comparing. Something like:
String stripDotGit(String s) {
RegExp pattern = RegExp(r'(.*)(\.git)$');
final RegExpMatch match = pattern.firstMatch(s);
if (match == null) {
return s;
}
return match.group(1);
}
As with any regex, we'd want to unit test this :)
c042117 to
4505736
Compare
|
I've split the error messages for specific use cases depending on whether
WDYT? |
686f5f4 to
0603920
Compare
|
@christopherfujino PTAL |
ab80bc9 to
b6bb501
Compare
|
This pull request is not suitable for automatic merging in its current state.
|
|
Reverting to unblock the plugins tree #83373 |
This PR makes
flutter upgradeto only work with "standard remotes", i.e., eitherhttps://github.com/flutter/flutter.git(or the SSH remotegit@github.com:flutter/flutter.git) or the one set as theFLUTTER_GIT_URLenvironment variable.Otherwise running
flutter upgrademakes the tool throw an error and exit(The.gitsuffix of either of the standard URLs can be used without).Error messages
The tool will display different error messages on different non-ideal user setups:
https://github.com/flutter/flutter.gitorgit@github.com:flutter/flutter.gitand havingFLUTTER_GIT_URLunset:FLUTTER_GIT_URLis set to different url than the tracking remote:FlutterVersion.repositoryUrlis null (The Flutter tool couldn't determine the upstream repository):Additional fixes
Additionally, replaces the git commands with
flutter channelupon detached HEAD state and clarifies the error message upon missing upstream for current branch.Related Issues
Fixes #78591.
Fixes #49713.
Fixes #79366.
Pre-launch Checklist
///).