mountGit method

Future<MountRecord> mountGit({
  1. required String url,
  2. required String nodeId,
  3. required String remotePath,
  4. String? name,
  5. String? branch,
  6. int? depth,
  7. bool readWrite = false,
  8. DriveProgress? onProgress,
})

Mounts a git repository onto remotePath of nodeId. The node clones the repo, so url must be reachable from the node.

Implementation

Future<MountRecord> mountGit({
  required String url,
  required String nodeId,
  required String remotePath,
  String? name,
  String? branch,
  int? depth,
  bool readWrite = false,
  DriveProgress? onProgress,
}) async {
  final mountName = name ?? _gitName(url);
  final endpoint = _endpointId(nodeId);
  final driveId = DriveId.scoped(endpoint: endpoint, name: mountName);
  final id = _mountId(nodeId, mountName);

  var record = MountRecord(
    id: id,
    nodeId: nodeId,
    name: mountName,
    kind: 'git',
    remotePath: remotePath,
    gitUrl: url,
    gitBranch: branch,
    readWrite: readWrite,
    driveId: driveId.value,
    mountedAt: DateTime.now(),
    syncState: SyncState(
      baselineRef: SyncRef.git('0'),
      status: SyncStatus.clean,
    ),
  );

  record = await _withSession(record, (rpc) async {
    _emit(onProgress, ProgressPhase.transferring, 'cloning $url');
    final head = await rpc.gitClone(url, branch: branch, depth: depth);
    _emit(onProgress, ProgressPhase.done, 'cloned');
    return record.copyWith(
      syncState: SyncState(
        baselineRef: SyncRef.git(head),
        currentRef: SyncRef.git(head),
        status: SyncStatus.clean,
        lastSyncedAt: DateTime.now(),
      ),
    );
  });

  store.mounts[id] = record;
  await store.save();
  return record;
}