Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shorebird_cli): add fetch to Git #1052

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/shorebird_cli/lib/src/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ class Git {
}
}

/// Fetch branches/tags from the repository at [directory].
Future<void> fetch({required String directory, List<String>? args}) async {
final arguments = ['fetch', ...?args];
final result = await process.run(
executable,
arguments,
workingDirectory: directory,
);
if (result.exitCode != 0) {
throw ProcessException(
executable,
arguments,
'${result.stderr}',
result.exitCode,
);
}
}

/// Returns the revision of the git repository located at [directory].
Future<String> revParse({
required String revision,
Expand Down
48 changes: 48 additions & 0 deletions packages/shorebird_cli/test/src/git_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,54 @@ void main() {
});
});

group('fetch', () {
const directory = 'repository';
test('executes correct command', () async {
await expectLater(
runWithOverrides(
() => git.fetch(directory: directory),
),
completes,
);
verify(
() => process.run(
'git',
['fetch'],
workingDirectory: directory,
),
).called(1);
});

test('executes correct command w/args', () async {
final args = ['--tags'];
await expectLater(
runWithOverrides(
() => git.fetch(directory: directory, args: args),
),
completes,
);
verify(
() => process.run(
'git',
['fetch', ...args],
workingDirectory: directory,
),
).called(1);
});

test('throws ProcessException if process exits with error', () async {
const error = 'oops';
when(() => processResult.exitCode).thenReturn(ExitCode.software.code);
when(() => processResult.stderr).thenReturn(error);
expect(
() => runWithOverrides(() => git.fetch(directory: directory)),
throwsA(
isA<ProcessException>().having((e) => e.message, 'message', error),
),
);
});
});

group('revParse', () {
const directory = './output';
const revision = 'revision';
Expand Down