-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(packages): ensure git dependencies are reachable (#379)
- Loading branch information
Showing
6 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
part of 'cli.dart'; | ||
|
||
/// {@template unreachable_git_dependency} | ||
/// Thrown when `flutter packages get` or `flutter pub get` | ||
/// encounters an unreachable git dependency. | ||
/// {@endtemplate} | ||
class UnreachableGitDependency implements Exception { | ||
/// {@macro unreachable_git_dependency} | ||
const UnreachableGitDependency({required this.remote}); | ||
|
||
/// The associated git remote [Uri]. | ||
final Uri remote; | ||
|
||
@override | ||
String toString() { | ||
return ''' | ||
$remote is unreachable. | ||
Make sure the remote exists and you have the correct access rights.'''; | ||
} | ||
} | ||
|
||
/// Git CLI | ||
class Git { | ||
/// Determine whether the [remote] is reachable. | ||
static Future<void> reachable(Uri remote) async { | ||
try { | ||
await _Cmd.run('git', ['ls-remote', '$remote', '--exit-code']); | ||
} catch (_) { | ||
throw UnreachableGitDependency(remote: remote); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:very_good_cli/src/cli/cli.dart'; | ||
|
||
void main() { | ||
group('Git', () { | ||
group('reachable', () { | ||
test('completes for a reachable remote', () async { | ||
await expectLater( | ||
Git.reachable( | ||
Uri.parse('https://github.com/verygoodopensource/very_good_cli'), | ||
), | ||
completes, | ||
); | ||
}); | ||
|
||
test('throws UnreachableGitDependency for an unreachable remote', | ||
() async { | ||
await expectLater( | ||
Git.reachable( | ||
Uri.parse('https://github.com/verygoodopensource/_very_good_cli'), | ||
), | ||
throwsA(isA<UnreachableGitDependency>()), | ||
); | ||
}); | ||
}); | ||
|
||
group('UnreachableGitDependency', () { | ||
test('has correct toString override', () { | ||
final remote = | ||
Uri.parse('https://github.com/verygoodopensource/_very_good_cli'); | ||
final exception = UnreachableGitDependency(remote: remote); | ||
expect( | ||
exception.toString(), | ||
equals( | ||
''' | ||
$remote is unreachable. | ||
Make sure the remote exists and you have the correct access rights.''', | ||
), | ||
); | ||
}); | ||
}); | ||
}); | ||
} |