conflicts method

Future<DriveChanges> conflicts(
  1. String mountId, {
  2. bool includeDiffs = false,
})

Lists every path that differs between the local copy and the node for a directory mount, grouped by which side changed — true conflicts (both sides), local-only changes (a sync would push), and remote-only changes (a sync would pull). Read-only: it performs no sync, resolve, or state change.

Without a trustworthy baseline snapshot the side cannot be determined, so the differing paths are returned in DriveChanges.unknown. With includeDiffs, the FileDiff of each diffable path is also computed within the same session and returned in DriveChanges.diffs — the conflicting paths when a baseline is known, or every differing path when it is not (so --diff is useful even for an unclassified, legacy mount).

Implementation

Future<DriveChanges> conflicts(
  String mountId, {
  bool includeDiffs = false,
}) async {
  final record = require(mountId);
  if (record.isGit) {
    throw DriveException(
      'drive conflicts is only supported for directory mounts',
    );
  }
  return _withSession(record, (rpc) async {
    final local = _localSource(record);
    final localManifest = await local.manifest();
    final originManifest = await ChannelContentSource(rpc).manifest();
    // Builds the per-path diffs for [paths] within this session, when asked.
    Future<Map<String, FileDiff>> diffsFor(List<String> paths) async {
      if (!includeDiffs || paths.isEmpty) return const {};
      final map = <String, FileDiff>{};
      for (final path in paths) {
        map[path] = await _buildFileDiff(
          record,
          rpc,
          local,
          localManifest,
          originManifest,
          path,
        );
      }
      return map;
    }

    final base = record.baselineManifest;
    if (base == null || base.hash() != record.syncState.baselineRef) {
      // No baseline snapshot: we can list differing paths but not classify
      // them. With --diff, still show each one's diff.
      final unknown = _contentDivergedPaths(localManifest, originManifest);
      return DriveChanges(unknown: unknown, diffs: await diffsFor(unknown));
    }
    final plan = _mergePlan(base, localManifest, originManifest);
    return DriveChanges(
      localOnly: [...plan.toRemote, ...plan.removeRemote]..sort(),
      remoteOnly: [...plan.toLocal, ...plan.removeLocal]..sort(),
      conflicts: plan.conflicts,
      diffs: await diffsFor(plan.conflicts),
    );
  });
}