run method

  1. @override
Future run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future run() async {
  var gitRootDir = GitRepository.findRootDir(Directory.current.path)!;
  var repo = await GitRepository.load(gitRootDir);

  var filePath = argResults!.arguments[0];
  var index = await repo.indexStorage.readIndex();

  var hash = await repo.rmFileFromIndex(index, filePath);
  if (hash == null) {
    print("fatal: pathspec '$filePath' did not match any files");
    return;
  }
  if (File(filePath).existsSync()) {
    await File(filePath).delete(recursive: true);
  }
  await repo.indexStorage.writeIndex(index);

  print("rm '${repo.toPathSpec(filePath)}'");

  // FIXME: Get proper pathSpec
  // FIXME: Handle glob patterns
  // FIXME: Handle .
}