stateOf method

Future<PatchState> stateOf(
  1. PatchFile patch
)

The state of patch against the lockfile and the project cache.

Implementation

Future<PatchState> stateOf(PatchFile patch) async {
  final locked = _lockedVersions()[patch.packageName];
  if (locked != null && locked != patch.versionOrRef) {
    return PatchState.stale;
  }
  final directory = _applyDirectory(patch);
  if (directory == null) {
    return locked == null ? PatchState.stale : PatchState.missing;
  }
  final path = patch.file.absolute.path;
  if (await git.succeeds([
    'apply',
    '--reverse',
    '--check',
    path,
  ], directory: directory)) {
    return PatchState.applied;
  }
  if (await git.succeeds(['apply', '--check', path], directory: directory)) {
    return PatchState.notApplied;
  }
  return PatchState.conflict;
}