mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
throw more specific toolexit when git fails during upgrade (#57162)
This commit is contained in:
parent
7706a97aba
commit
a2f5364dc0
@ -219,12 +219,23 @@ class UpgradeCommandRunner {
|
|||||||
workingDirectory: workingDirectory,
|
workingDirectory: workingDirectory,
|
||||||
);
|
);
|
||||||
revision = result.stdout.trim();
|
revision = result.stdout.trim();
|
||||||
} on Exception {
|
} on Exception catch (e) {
|
||||||
|
final String errorString = e.toString();
|
||||||
|
if (errorString.contains('fatal: HEAD does not point to a branch')) {
|
||||||
|
throwToolExit(
|
||||||
|
'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'
|
||||||
|
);
|
||||||
|
} else if (errorString.contains('fatal: no upstream configured for branch')) {
|
||||||
throwToolExit(
|
throwToolExit(
|
||||||
'Unable to upgrade Flutter: no origin repository configured. '
|
'Unable to upgrade Flutter: no origin repository configured. '
|
||||||
"Run 'git remote add origin "
|
'Run \'git remote add origin '
|
||||||
"https://github.com/flutter/flutter' in $workingDirectory",
|
'https://github.com/flutter/flutter\' in $workingDirectory');
|
||||||
);
|
} else {
|
||||||
|
throwToolExit(errorString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return revision;
|
return revision;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ void main() {
|
|||||||
Platform: () => fakePlatform,
|
Platform: () => fakePlatform,
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('fetchRemoteRevision', () async {
|
testUsingContext('fetchRemoteRevision returns revision if git succeeds', () async {
|
||||||
const String revision = 'abc123';
|
const String revision = 'abc123';
|
||||||
when(processManager.run(
|
when(processManager.run(
|
||||||
<String>['git', 'fetch', '--tags'],
|
<String>['git', 'fetch', '--tags'],
|
||||||
@ -185,6 +185,60 @@ void main() {
|
|||||||
Platform: () => fakePlatform,
|
Platform: () => fakePlatform,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('fetchRemoteRevision throws toolExit if HEAD is detached', () async {
|
||||||
|
when(processManager.run(
|
||||||
|
<String>['git', 'fetch', '--tags'],
|
||||||
|
environment:anyNamed('environment'),
|
||||||
|
workingDirectory: anyNamed('workingDirectory')),
|
||||||
|
).thenAnswer((Invocation invocation) async {
|
||||||
|
return FakeProcessResult()..exitCode = 0;
|
||||||
|
});
|
||||||
|
when(processManager.run(
|
||||||
|
<String>['git', 'rev-parse', '--verify', '@{u}'],
|
||||||
|
environment:anyNamed('environment'),
|
||||||
|
workingDirectory: anyNamed('workingDirectory')),
|
||||||
|
).thenThrow(const ProcessException(
|
||||||
|
'git',
|
||||||
|
<String>['rev-parse', '--verify', '@{u}'],
|
||||||
|
'fatal: HEAD does not point to a branch',
|
||||||
|
));
|
||||||
|
expect(
|
||||||
|
() async => await realCommandRunner.fetchRemoteRevision(),
|
||||||
|
throwsToolExit(message: 'You are not currently on a release branch.'),
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
Platform: () => fakePlatform,
|
||||||
|
});
|
||||||
|
|
||||||
|
testUsingContext('fetchRemoteRevision throws toolExit if no upstream configured', () async {
|
||||||
|
when(processManager.run(
|
||||||
|
<String>['git', 'fetch', '--tags'],
|
||||||
|
environment:anyNamed('environment'),
|
||||||
|
workingDirectory: anyNamed('workingDirectory')),
|
||||||
|
).thenAnswer((Invocation invocation) async {
|
||||||
|
return FakeProcessResult()..exitCode = 0;
|
||||||
|
});
|
||||||
|
when(processManager.run(
|
||||||
|
<String>['git', 'rev-parse', '--verify', '@{u}'],
|
||||||
|
environment:anyNamed('environment'),
|
||||||
|
workingDirectory: anyNamed('workingDirectory')),
|
||||||
|
).thenThrow(const ProcessException(
|
||||||
|
'git',
|
||||||
|
<String>['rev-parse', '--verify', '@{u}'],
|
||||||
|
'fatal: no upstream configured for branch',
|
||||||
|
));
|
||||||
|
expect(
|
||||||
|
() async => await realCommandRunner.fetchRemoteRevision(),
|
||||||
|
throwsToolExit(
|
||||||
|
message: 'Unable to upgrade Flutter: no origin repository configured\.',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
Platform: () => fakePlatform,
|
||||||
|
});
|
||||||
|
|
||||||
testUsingContext('git exception during attemptReset throwsToolExit', () async {
|
testUsingContext('git exception during attemptReset throwsToolExit', () async {
|
||||||
const String revision = 'abc123';
|
const String revision = 'abc123';
|
||||||
const String errorMessage = 'fatal: Could not parse object ´$revision´';
|
const String errorMessage = 'fatal: Could not parse object ´$revision´';
|
||||||
|
Loading…
Reference in New Issue
Block a user