Skip to content

Conversation

@christopherfujino
Copy link
Contributor

Description

If the user's git repo is in a detached HEAD state (which happens after using flutter version <tag> or git checkout <tag>) and they try to flutter upgrade, they will receive in an incorrect error message: Unable to upgrade Flutter: no origin repository configured.

This PR catches the process exception, and throws specific tool exits if either their head is detached or they don't have an upstream configured, else the original git error message is surfaced.

Related Issues

Fixes #56853.

Tests

I added two new unit tests to validate the new tool exit messages.

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label May 13, 2020
@christopherfujino christopherfujino requested a review from jmagman May 13, 2020 21:10
);
} on Exception catch (e){
final String errorString = e.toString();
if (RegExp(r'fatal: HEAD does not point to a branch').hasMatch(errorString)) {
Copy link
Member

Choose a reason for hiding this comment

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

errorString.contains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

'check out an official branch\n(\'stable\', \'beta\', \'dev\', or \'master\') '
'and retry, for example \'git checkout stable\'.'
);
} else if (RegExp(r'fatal: no upstream configured for branch').hasMatch(errorString)) {
Copy link
Member

Choose a reason for hiding this comment

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

contains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"Run 'git remote add origin "
"https://github.com/flutter/flutter' in $workingDirectory",
);
} on Exception catch (e){
Copy link
Member

Choose a reason for hiding this comment

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

Missing space between ( and {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 226 to 228
'You are not currently on a release branch. Use git to '
'check out an official branch\n(\'stable\', \'beta\', \'dev\', or \'master\') '
'and retry, for example \'git checkout stable\'.'
Copy link
Member

Choose a reason for hiding this comment

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

Based on an audit of user messages, how about:

'You are not currently on a release branch. Use git to '
'check out an official branch (\'stable\', \'beta\', \'dev\', or \'master\') '
'and retry, for example:\n'
'  git checkout stable'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM

@christopherfujino christopherfujino merged commit a2f5364 into flutter:master May 14, 2020
@christopherfujino christopherfujino deleted the improve-error-message-when-upgrading branch May 14, 2020 18:03
pcsosinski pushed a commit to pcsosinski/flutter that referenced this pull request May 26, 2020
pcsosinski pushed a commit that referenced this pull request May 28, 2020
* fix segment hit test behavior (#57461)

* Making DropdownButtonFormField to re-render if parent widget changes (#57037)

* Update DropdownButtonFormField's state if widget updates

Co-authored-by: Shi-Hao Hong <[email protected]>

* throw more specific toolexit when git fails during upgrade (#57162)

* [flutter_tools] Refresh VM state before executing hot reload (#53960)

* Update engine hash for 1.17.2

* Remove MaterialControls from examples/flutter_view (#57621)

Co-authored-by: Jenn Magder <[email protected]>

* Prevent building non-android plugins in build aar (#58018)

* Allow FLUTTER_APPLICATION_PATH to be null for misconfigured Xcode projects (#57701)

* Don't import plugins that don't support android in settings.gradle (#54407)

Co-authored-by: LongCatIsLooong <[email protected]>
Co-authored-by: Pedro Massango <[email protected]>
Co-authored-by: Shi-Hao Hong <[email protected]>
Co-authored-by: Christopher Fujino <[email protected]>
Co-authored-by: Jason Simmons <[email protected]>
Co-authored-by: stuartmorgan <[email protected]>
Co-authored-by: Jenn Magder <[email protected]>
Co-authored-by: Emmanuel Garcia <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

flutter upgrade gives wrong error with detached head: "Unable to upgrade Flutter: no origin repository configured"

5 participants