ensureGitAttributes creates the .gitattributes file in the cache directory if it doesn't exist
()
| 145 | |
| 146 | // ensureGitAttributes creates the .gitattributes file in the cache directory if it doesn't exist |
| 147 | func (c *ImportCache) ensureGitAttributes() error { |
| 148 | gitAttributesPath := filepath.Join(c.GetCacheDir(), ".gitattributes") |
| 149 | |
| 150 | // Check if .gitattributes already exists |
| 151 | if _, err := os.Stat(gitAttributesPath); err == nil { |
| 152 | // File already exists, nothing to do |
| 153 | return nil |
| 154 | } |
| 155 | |
| 156 | // Ensure cache root directory exists |
| 157 | cacheDir := c.GetCacheDir() |
| 158 | if err := os.MkdirAll(cacheDir, constants.DirPermSensitive); err != nil { |
| 159 | return err |
| 160 | } |
| 161 | |
| 162 | // Create .gitattributes file with content |
| 163 | content := `# Mark all cached import files as generated |
| 164 | * linguist-generated=true |
| 165 | |
| 166 | # Use 'ours' merge strategy to keep local cached versions |
| 167 | * merge=ours |
| 168 | ` |
| 169 | |
| 170 | if err := os.WriteFile(gitAttributesPath, []byte(content), constants.FilePermPublic); err != nil { |
| 171 | return err |
| 172 | } |
| 173 | |
| 174 | importCacheLog.Printf("Created .gitattributes in cache directory: %s", gitAttributesPath) |
| 175 | return nil |
| 176 | } |
no test coverage detected