diff options
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( `\`, `\\`, " ", `\ `, "#", `\#`, "!", `\!`, |
