checkout method

Future<int?> checkout(
  1. String path
)

Implementation

Future<int?> checkout(String path) async {
  path = normalizePath(path);

  var tree = await headTree();
  if (tree == null) {
    return null;
  }

  var spec = path.substring(workTree.length);
  var objRes = await objStorage.refSpec(tree, spec);
  var obj = objRes.get();

  if (obj is GitBlob) {
    await fs.directory(p.dirname(path)).create(recursive: true);
    await fs.file(path).writeAsBytes(obj.blobData);
    return 1;
  }

  var index = GitIndex(versionNo: 2);
  var numFiles = await _checkoutTree(spec, obj as GitTree, index);
  await indexStorage.writeIndex(index);

  return numFiles;
}