updateBaseline method
Creates the baseline when there is none, and adds packages that pub
downloaded since the last update. With rebuild, discards every edit
in the cache and records a fresh baseline.
Implementation
Future<void> updateBaseline({bool rebuild = false}) async {
if (!exists) {
throw DpkException(
'The project cache ${_display(cachePath)} is empty. Run "dpk get" '
'first.',
);
}
if (rebuild && hasBaseline) {
await git(['checkout', '--', '.'], directory: cachePath);
await git(['clean', '-fdq', '--', 'hosted'], directory: cachePath);
for (final checkout in _gitCheckouts()) {
await git(['checkout', '--', '.'], directory: checkout);
await git(['clean', '-fdq'], directory: checkout);
}
await Directory(p.join(cachePath, '.git')).delete(recursive: true);
}
if (!hasBaseline) {
await git(['init', '--quiet'], directory: cachePath);
File(p.join(cachePath, '.git', 'info', 'exclude'))
..createSync(recursive: true)
..writeAsStringSync('/*\n!/hosted/\n');
await git(['add', '--all', '--', 'hosted'], directory: cachePath);
await git.commit(_baselineMessage, directory: cachePath);
return;
}
final newPackages = await _newPackageFolders();
if (newPackages.isEmpty) {
return;
}
await git(['add', '--all', '--', ...newPackages], directory: cachePath);
await git.commit(_baselineMessage, directory: cachePath);
}