prepareFiles method
Prepare files for the task.
If backup
is true, stash the current state of the repository.
Returns a GitContext object with the current state of the repository.
Implementation
Future<GitContext> prepareFiles({
bool backup = true,
}) async {
final context = GitContextSetter();
try {
context.partiallyStagedFiles = await partiallyStagedFiles();
if (context.partiallyStagedFiles case final partially
when partially.isNotEmpty) {
logger
.detail('Preparing partial files for patch (${partially.length})');
for (final file in partially) {
logger.detail(' $file');
}
final filePaths = processRenames(partially);
logger.detail('Processed files (${partially.length})');
for (final file in filePaths) {
logger.detail(' $file');
}
logger.detail('Creating patch');
await patch(filePaths);
}
if (!backup) {
return context.toImmutable();
}
context
..mergeHead = mergeHead
..mergeMode = mergeMode
..mergeMsg = mergeMsg
..deletedFiles = await getDeletedFiles()
..stashHash = await createStash()
..nonStagedFiles = await nonStagedFiles() ?? []
..hidePartiallyStaged = backup;
} catch (e) {
logger
..err('Failed to prepare files')
..detail('Error: $e');
throw Exception('Failed to prepare files');
}
return context.toImmutable();
}