Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Aug 8, 2023
1 parent b296d86 commit b74a6f9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
9 changes: 5 additions & 4 deletions packages/shorebird_cli/lib/src/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ class Git {
}
}

/// List all branches in the git repository located at [directory] that match
/// the [pattern].
Future<String> listBranches({
/// Iterate over all refs that match [pattern] and show them
/// according to the given [format].
Future<String> forEachRef({
required String directory,
required String format,
required String pattern,
}) async {
final arguments = ['branch', '--all', '--list', pattern];
final arguments = ['for-each-ref', '--format', format, pattern];
final result = await process.run(
executable,
arguments,
Expand Down
32 changes: 23 additions & 9 deletions packages/shorebird_cli/test/src/git_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,35 @@ void main() {
});
});

group('listBranches', () {
group('forEachRef', () {
const directory = 'repository';
const pattern = 'pattern';
const format = '%(refname:short)';
const pattern = 'refs/remotes/origin/flutter_release/*';
const output = '''
* main
stable
remotes/origin/HEAD -> origin/main''';
origin/flutter_release/3.10.0
origin/flutter_release/3.10.1
origin/flutter_release/3.10.2
origin/flutter_release/3.10.3
origin/flutter_release/3.10.4
origin/flutter_release/3.10.5
origin/flutter_release/3.10.6''';
test('executes correct command', () async {
when(() => processResult.stdout).thenReturn(output);
await expectLater(
runWithOverrides(
() => git.listBranches(pattern: pattern, directory: directory),
() => git.forEachRef(
pattern: pattern,
format: format,
directory: directory,
),
),
completion(equals(output)),
completion(equals(output.trim())),
);
verify(
() => process.run(
'git',
['branch', '--all', '--list', pattern],
['for-each-ref', '--format', format, pattern],
workingDirectory: directory,
),
).called(1);
Expand All @@ -219,7 +229,11 @@ void main() {
when(() => processResult.stderr).thenReturn(error);
expect(
() => runWithOverrides(
() => git.listBranches(pattern: pattern, directory: directory),
() => git.forEachRef(
pattern: pattern,
format: format,
directory: directory,
),
),
throwsA(
isA<ProcessException>().having((e) => e.message, 'message', error),
Expand Down

0 comments on commit b74a6f9

Please sign in to comment.