(ctx context.Context, repo, destination string)
| 369 | } |
| 370 | |
| 371 | func shallowCloneTargetRepo(ctx context.Context, repo, destination string) error { |
| 372 | if err := os.RemoveAll(destination); err != nil { |
| 373 | return fmt.Errorf("failed to clean previous checkout %s: %w", destination, err) |
| 374 | } |
| 375 | |
| 376 | // Use a sparse shallow clone to minimize bandwidth and disk usage when update mode |
| 377 | // needs a temporary checkout solely for workflow and agent files. |
| 378 | cmd := exec.CommandContext(ctx, "gh", "repo", "clone", repo, destination, "--", "--depth=1", "--filter=blob:none", "--sparse") |
| 379 | output, err := cmd.CombinedOutput() |
| 380 | if err != nil { |
| 381 | trimmed := strings.TrimSpace(string(output)) |
| 382 | if trimmed == "" { |
| 383 | return fmt.Errorf("failed to shallow clone %s: %w", repo, err) |
| 384 | } |
| 385 | return fmt.Errorf("failed to shallow clone %s: %w: %s", repo, err, trimmed) |
| 386 | } |
| 387 | |
| 388 | sparseArgs := []string{"-C", destination, "sparse-checkout", "set", ".github"} |
| 389 | sparseCmd := exec.CommandContext(ctx, "git", sparseArgs...) |
| 390 | output, err = sparseCmd.CombinedOutput() |
| 391 | if err != nil { |
| 392 | trimmed := strings.TrimSpace(string(output)) |
| 393 | if trimmed == "" { |
| 394 | return fmt.Errorf("failed to configure sparse checkout for %s: %w", repo, err) |
| 395 | } |
| 396 | return fmt.Errorf("failed to configure sparse checkout for %s: %w: %s", repo, err, trimmed) |
| 397 | } |
| 398 | return nil |
| 399 | } |
| 400 | |
| 401 | func sanitizeRepoPath(repo string) string { |
| 402 | replacer := strings.NewReplacer("/", "__", "\\", "__", ":", "__", "@", "__") |
no test coverage detected