fix(init): handle read-only gitignore gracefully in stealth mode (#663)

When the global gitignore file is read-only (e.g., symlink to immutable
location), print manual instructions instead of failing with an error.
This commit is contained in:
Doug Campos
2025-12-20 19:43:43 -05:00
committed by GitHub
parent 5b2a516aca
commit c7c212f8a1
2 changed files with 102 additions and 1 deletions

View File

@@ -1503,7 +1503,19 @@ func setupGlobalGitIgnore(homeDir string, projectPath string, verbose bool) erro
// Write the updated ignore file
// #nosec G306 - config file needs 0644
if err := os.WriteFile(ignorePath, []byte(newContent), 0644); err != nil {
return fmt.Errorf("failed to write global gitignore: %w", err)
fmt.Printf("\nUnable to write to %s (file is read-only)\n\n", ignorePath)
fmt.Printf("To enable stealth mode, add these lines to your global gitignore:\n\n")
if !hasBeads || !hasClaude {
fmt.Printf("# Beads stealth mode: %s\n", projectPath)
}
if !hasBeads {
fmt.Printf("%s\n", beadsPattern)
}
if !hasClaude {
fmt.Printf("%s\n", claudePattern)
}
fmt.Println()
return nil
}
if verbose {