MCPcopy Create free account
hub / github.com/github/gh-aw / shallowCloneTargetRepo

Function shallowCloneTargetRepo

pkg/cli/update_command.go:371–399  ·  view source on GitHub ↗
(ctx context.Context, repo, destination string)

Source from the content-addressed store, hash-verified

369}
370
371func 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
401func sanitizeRepoPath(repo string) string {
402 replacer := strings.NewReplacer("/", "__", "\\", "__", ":", "__", "@", "__")

Callers 5

runUpdateForTargetRepoFunction · 0.85
prepareDeployCheckoutFunction · 0.85
scanUpgradeRepoFunction · 0.85
runUpgradeForTargetRepoFunction · 0.85
previewOrgRepoUpdatesFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected