restoreStash method

Future<bool> restoreStash()

Implementation

Future<bool> restoreStash() async {
  final stashIndex = await stash();

  if (stashIndex == null) {
    return false;
  }

  // hard reset
  final reset = await Process.run('git', [
    'reset',
    '--hard',
    'HEAD',
  ]);

  if (reset.exitCode != 0) {
    logger
      ..err('Failed to reset')
      ..detail('Error: ${reset.stderr}');
    return false;
  }

  // apply stash
  final apply = await Process.run('git', [
    'stash',
    'apply',
    '--quiet',
    '--index',
    '$stashIndex',
  ]);

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

  return true;
}