keepWorktree method

Future<void> keepWorktree()

Keeps the worktree intact but clears the session.

Implementation

Future<void> keepWorktree() async {
  final session = currentSession.value;
  if (session == null) return;

  try {
    Directory.current = Directory(session.originalCwd);
    currentSession.value = null;
    onSaveProjectConfig?.call(null);

    _logForDebugging(
      'Linked worktree preserved at: ${session.worktreePath}'
      '${session.worktreeBranch != null ? ' on branch: ${session.worktreeBranch}' : ''}',
    );
    _logForDebugging(
      'You can continue working there by running: cd ${session.worktreePath}',
    );
  } catch (e) {
    _logForDebugging('Error keeping worktree: $e', level: 'error');
  }
}