restoreWorktreeForResume function
void
restoreWorktreeForResume(})
Restore worktree working directory on resume.
Implementation
void restoreWorktreeForResume(
Map<String, dynamic>? worktreeSession, {
void Function(String)? setCwd,
void Function(String)? setOriginalCwd,
void Function(Map<String, dynamic>?)? saveWorktreeState,
Map<String, dynamic>? Function()? getCurrentWorktreeSession,
void Function(Map<String, dynamic>?)? restoreWorktreeSession,
void Function()? clearCaches,
}) {
// If --worktree already created a fresh worktree, it takes precedence.
final fresh = getCurrentWorktreeSession?.call();
if (fresh != null) {
saveWorktreeState?.call(fresh);
return;
}
if (worktreeSession == null) return;
final worktreePath = worktreeSession['worktreePath'] as String?;
if (worktreePath == null) return;
try {
Directory.current = worktreePath;
} catch (_) {
// Directory is gone.
saveWorktreeState?.call(null);
return;
}
setCwd?.call(worktreePath);
setOriginalCwd?.call(Directory.current.path);
restoreWorktreeSession?.call(worktreeSession);
clearCaches?.call();
}