(ctx context.Context, repo drivers.RepoStore)
| 146 | } |
| 147 | |
| 148 | func SetupGitIgnore(ctx context.Context, repo drivers.RepoStore) error { |
| 149 | // Ensure .gitignore exists and contains necessary entries |
| 150 | contents, err := repo.Get(ctx, ".gitignore") |
| 151 | if err != nil { |
| 152 | if !strings.Contains(err.Error(), "no such file") { |
| 153 | return err |
| 154 | } |
| 155 | // Create .gitignore if it does not exist |
| 156 | err = repo.Put(ctx, ".gitignore", strings.NewReader(".DS_Store\n\n# Rill\n.env\ntmp\n")) |
| 157 | if err != nil { |
| 158 | return err |
| 159 | } |
| 160 | return nil |
| 161 | } |
| 162 | |
| 163 | gitIgnoreContent := strings.ReplaceAll(contents, "\r\n", "\n") |
| 164 | gitIgnoreEntries := strings.Split(gitIgnoreContent, "\n") |
| 165 | var added bool |
| 166 | for _, path := range []string{".DS_Store", ".env", "tmp"} { |
| 167 | if slices.Contains(gitIgnoreEntries, path) { |
| 168 | continue // already exists |
| 169 | } |
| 170 | added = true |
| 171 | gitIgnoreContent += fmt.Sprintf("\n%s", path) |
| 172 | } |
| 173 | if !added { |
| 174 | return nil // nothing to add |
| 175 | } |
| 176 | return repo.Put(ctx, ".gitignore", strings.NewReader(gitIgnoreContent)) |
| 177 | } |
no test coverage detected