apply method

  1. @override
Future<void> apply({
  1. required Directory directory,
  2. required Logger? logger,
})
override

Apply this preparation step to the source directory.

Implementation

@override
Future<void> apply({
  required Directory directory,
  required Logger? logger,
}) async {
  for (final patchPath in paths) {
    final patchFile = File(patchPath);
    if (!patchFile.existsSync()) {
      throw SourcePreparationException('Patch file not found: $patchPath');
    }

    logger?.info('Applying patch: ${p.basename(patchPath)}');

    final args = [
      if (reverse) '--reverse',
      '--directory=${directory.path}',
      '--input=${patchFile.path}',
      '--strip=1',
    ];

    final result = await ProcessRunner(
      logger: logger,
    ).runStreaming('patch', args, requireSuccess: false);
    if (result.exitCode != 0) {
      throw SourcePreparationException(
        'Failed to apply patch ${p.basename(patchPath)}: ${result.stderr.trim()}',
      );
    }
  }
}