patch method

Future<void> patch(
  1. List<String> filePaths
)

Implementation

Future<void> patch(
  List<String> filePaths,
) async {
  final result = await Process.run(
    'git',
    [
      'diff',
      ...gitDiffArgs,
      '--output',
      _patchPath,
      '--',
      ...filePaths,
    ],
  );

  if (result.exitCode != 0) {
    logger
      ..err('Failed to create patch files')
      ..detail('Error: ${result.stderr}')
      ..detail('Files (${filePaths.length})');
    for (final file in filePaths) {
      logger.detail('  - $file');
    }
    throw Exception('Failed to create path files');
  }

  logger.detail('Create patch output: ${result.stdout}');

  // ensure file exists
  if (!fs.file(_patchPath).existsSync()) {
    logger
      ..err('Failed to create patch')
      ..detail('Output: ${result.stdout}');
    throw Exception('Failed to create patch');
  }
}