diff options
| author | t <t@tjp.lol> | 2026-07-13 11:38:42 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-07-31 16:18:30 -0600 |
| commit | fd8b956ab23176e669c29e4086c1f016be419ed9 (patch) | |
| tree | 2ca22b68597e2a7bc43643822cd0e78e0ea768a1 /main.go | |
| parent | 9f4971c92628052b8c51342b83b9aef966a4c318 (diff) | |
Skip symlinked outputs in the managed .gitignore
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -858,12 +858,40 @@ func (s *site) gitignore(outputs []string) ([]byte, error) { if strings.ContainsAny(output, "\r\n") { return nil, fmt.Errorf("cannot add output to .gitignore: %q", output) } + symlinked, err := s.hasSymlinkedParent(output) + if err != nil { + return nil, err + } + if symlinked { + continue + } kept.WriteString("/" + escapeGitignore(output) + "\n") } kept.WriteString(gitignoreEnd + "\n") return []byte(kept.String()), nil } +func (s *site) hasSymlinkedParent(output string) (bool, error) { + current := s.root + for _, part := range strings.Split(path.Dir(output), "/") { + if part == "." { + continue + } + current = filepath.Join(current, part) + info, err := os.Lstat(current) + if errors.Is(err, os.ErrNotExist) { + return false, nil + } + if err != nil { + return false, err + } + if info.Mode()&os.ModeSymlink != 0 { + return true, nil + } + } + return false, nil +} + func escapeGitignore(value string) string { return strings.NewReplacer( `\`, `\\`, " ", `\ `, "#", `\#`, "!", `\!`, |
