(gitRoot string)
| 344 | } |
| 345 | |
| 346 | func ensureUpdateTargetRepoGitignore(gitRoot string) (string, error) { |
| 347 | updatesDir := filepath.Join(gitRoot, updateTargetRepoCheckoutDir) |
| 348 | if err := os.MkdirAll(updatesDir, constants.DirPermPublic); err != nil { |
| 349 | return "", fmt.Errorf("failed to create %s: %w", updateTargetRepoCheckoutDir, err) |
| 350 | } |
| 351 | |
| 352 | gitignorePath := filepath.Join(updatesDir, ".gitignore") |
| 353 | if _, err := os.Stat(gitignorePath); err == nil { |
| 354 | return updatesDir, nil |
| 355 | } else if !errors.Is(err, os.ErrNotExist) { |
| 356 | return "", fmt.Errorf("failed to stat %s: %w", gitignorePath, err) |
| 357 | } |
| 358 | |
| 359 | const gitignoreContent = `# Ignore checked-out repositories used by 'gh aw update --repo' |
| 360 | * |
| 361 | |
| 362 | # Keep this file in version control |
| 363 | !.gitignore |
| 364 | ` |
| 365 | if err := os.WriteFile(gitignorePath, []byte(gitignoreContent), constants.FilePermSensitive); err != nil { |
| 366 | return "", fmt.Errorf("failed to write %s: %w", gitignorePath, err) |
| 367 | } |
| 368 | return updatesDir, nil |
| 369 | } |
| 370 | |
| 371 | func shallowCloneTargetRepo(ctx context.Context, repo, destination string) error { |
| 372 | if err := os.RemoveAll(destination); err != nil { |
no test coverage detected