getWorktreeDir method

Directory getWorktreeDir(
  1. String repoPath,
  2. String ref
)

Gets the worktree directory for a specific git ref Sanitizes the ref name to be safe for use in file paths

Implementation

Directory getWorktreeDir(String repoPath, String ref) {
  final repoCacheDir = getRepositoryCacheDir(repoPath);
  // Sanitize ref name: replace invalid characters with underscores
  final sanitizedRef = ref.replaceAll(RegExp(r'[<>:"|?*\x00-\x1f]'), '_');
  return Directory(join(repoCacheDir.path, 'worktrees', sanitizedRef));
}