writeObjects method

Future<Map<String, String>> writeObjects(
  1. List<String> paths
)

Given a list of paths, write those files to the object store and return a Map where the key is the input path and the value is the SHA of the newly written object.

Implementation

Future<Map<String, String>> writeObjects(List<String> paths) async {
  final args = [
    'hash-object',
    '-t',
    'blob',
    '-w',
    '--no-filters',
    '--',
    ...paths
  ];

  final pr = await runCommand(args);
  final val = (pr.stdout as String).trim();
  final shas = val.split(RegExp(r'\s+'));
  assert(shas.length == paths.length);
  assert(shas.every(isValidSha));
  final map = <String, String>{};
  for (var i = 0; i < shas.length; i++) {
    map[paths[i]] = shas[i];
  }
  return map;
}