summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/main.go b/main.go
index 299724e..96c1115 100644
--- a/main.go
+++ b/main.go
@@ -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(
`\`, `\\`, " ", `\ `, "#", `\#`, "!", `\!`,