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

Method ensureGitAttributes

pkg/parser/import_cache.go:147–176  ·  view source on GitHub ↗

ensureGitAttributes creates the .gitattributes file in the cache directory if it doesn't exist

()

Source from the content-addressed store, hash-verified

145
146// ensureGitAttributes creates the .gitattributes file in the cache directory if it doesn't exist
147func (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}

Callers 1

SetMethod · 0.95

Calls 2

GetCacheDirMethod · 0.95
PrintfMethod · 0.45

Tested by

no test coverage detected