exitRestoredWorktree function

void exitRestoredWorktree({
  1. Map<String, dynamic>? getCurrentWorktreeSession()?,
  2. void restoreWorktreeSession(
    1. Map<String, dynamic>?
    )?,
  3. void setCwd(
    1. String
    )?,
  4. void setOriginalCwd(
    1. String
    )?,
  5. void clearCaches()?,
})

Undo restoreWorktreeForResume before a mid-session /resume switches to another session.

Implementation

void exitRestoredWorktree({
  Map<String, dynamic>? Function()? getCurrentWorktreeSession,
  void Function(Map<String, dynamic>?)? restoreWorktreeSession,
  void Function(String)? setCwd,
  void Function(String)? setOriginalCwd,
  void Function()? clearCaches,
}) {
  final current = getCurrentWorktreeSession?.call();
  if (current == null) return;

  restoreWorktreeSession?.call(null);
  clearCaches?.call();

  final originalCwd = current['originalCwd'] as String?;
  if (originalCwd == null) return;

  try {
    Directory.current = originalCwd;
  } catch (_) {
    return;
  }
  setCwd?.call(originalCwd);
  setOriginalCwd?.call(Directory.current.path);
}