apply method
Applies every patch that is not applied yet, and returns how many were.
With force, a package whose edits conflict with its patch is reset to
the baseline first. Throws a DpkException for stale or conflicting
patches.
Implementation
Future<int> apply({bool force = false}) async {
var count = 0;
final problems = <String>[];
for (final patch in patches()) {
var state = await stateOf(patch);
if (state == PatchState.conflict && force) {
await _reset(patch);
state = await stateOf(patch);
}
switch (state) {
case PatchState.applied:
continue;
case PatchState.notApplied:
await git([
'apply',
'--whitespace=nowarn',
patch.file.absolute.path,
], directory: _applyDirectory(patch)!);
count++;
case PatchState.stale:
problems.add(_staleMessage(patch));
case PatchState.missing:
problems.add(
'${patch.relativePath}: ${patch.packageName} '
'${patch.versionOrRef} is not in the project cache. Run "dpk get".',
);
case PatchState.conflict:
problems.add(
'${patch.relativePath} does not apply: ${patch.folder} has edits '
'that are not in the patch. Run "dpk patch generate" to save '
'them, or "dpk patch apply --force" to discard them.',
);
}
}
if (problems.isNotEmpty) {
throw DpkException(problems.join('\n'));
}
return count;
}