commitFiles method

String commitFiles(
  1. String slug,
  2. Map<String, String> files, {
  3. String branch = 'main',
  4. String message = 'test',
})

Commits files (path → text) onto branch, creating it if needed. The direct way for a test to play the part of a competing writer.

Implementation

String commitFiles(
  String slug,
  Map<String, String> files, {
  String branch = 'main',
  String message = 'test',
}) {
  final r = repo(slug);
  final ref = 'heads/$branch';
  final parent = r.refs[ref];
  final base = parent == null
      ? <String, String>{}
      : {...trees[commits[parent]!.treeSha]!};
  for (final file in files.entries) {
    base[file.key] = _putBlob(utf8.encode(file.value));
  }
  final treeSha = _putTree(base);
  final commitSha = _putCommit(FakeCommit(treeSha, [?parent], message));
  r.refs[ref] = commitSha;
  return commitSha;
}