isFileDeleted method

Future<bool> isFileDeleted(
  1. String filePath
)

Check if a file was deleted in the staged changes.

Implementation

Future<bool> isFileDeleted(String filePath) async {
  final cwd = getAttributionRepoRoot();

  try {
    final result = await Process.run(gitExe, [
      'diff',
      '--cached',
      '--name-status',
      '--',
      filePath,
    ], workingDirectory: cwd);

    if (result.exitCode == 0 && (result.stdout as String).isNotEmpty) {
      return (result.stdout as String).trim().startsWith('D\t');
    }
  } catch (_) {
    // Ignore errors.
  }

  return false;
}