releaseBackup method
Rolls the repository back to backup unless the hook succeeded, then
releases the snapshot.
The ref is deliberately left in place when a restore fails -- that is the one case where the user's only remaining copy of their work is the snapshot itself.
Implementation
@visibleForTesting
Future<void> releaseBackup(String? backup, {required bool succeeded}) async {
if (backup == null) return;
if (succeeded) {
await git.dropBackup();
return;
}
logger.detail('Hook did not succeed, restoring $backup');
if (await git.restoreBackup(backup)) {
logger.detail('Restored the index and working tree');
await git.dropBackup();
return;
}
logger.err(
'Failed to restore your files after the hook did not succeed.\n'
'Your work is safe in a backup. Recover it by running:\n'
' git stash apply ${GitService.backupRef}',
);
}