applyPatch method

Future<bool> applyPatch()

Implementation

Future<bool> applyPatch() async {
  final patch = _patchPath;
  logger.detail('Applying patch from $patch');
  final firstTry = await Process.run(
    'git',
    [
      'apply',
      '-v',
      '--whitespace=nowarn',
      '--recount',
      '--unidiff-zero',
      patch,
    ],
  );

  if (firstTry.exitCode == 0) {
    return true;
  }

  logger
    ..detail('First patch try failed')
    ..detail('Error: ${firstTry.stderr}');

  // retry with --3way
  final secondTry = await Process.run(
    'git',
    [
      'apply',
      '-v',
      '--whitespace=nowarn',
      '--recount',
      '--unidiff-zero',
      '--3way',
      patch,
    ],
  );

  if (secondTry.exitCode != 0) {
    logger
      ..err('Failed to apply patch')
      ..detail('Error: ${secondTry.stderr}');
  }

  return false;
}