restoreWorktreeForResume function

void restoreWorktreeForResume(
  1. Map<String, dynamic>? worktreeSession, {
  2. void setCwd(
    1. String
    )?,
  3. void setOriginalCwd(
    1. String
    )?,
  4. void saveWorktreeState(
    1. Map<String, dynamic>?
    )?,
  5. Map<String, dynamic>? getCurrentWorktreeSession()?,
  6. void restoreWorktreeSession(
    1. Map<String, dynamic>?
    )?,
  7. void clearCaches()?,
})

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();
}