~james/core

core/gitutil/readme.go -rw-r--r-- 538 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 14 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package gitutil

import (
	"regexp"

	"github.com/go-git/go-git/v5/plumbing/filemode"
)

var readmePattern = regexp.MustCompile(`(?i)^readme(?:\.[^.]+)?$`)

// IsReadmeFile reports whether name/mode identifies a readme blob. The git
// mode is checked so directories or symlinks named "readme" are filtered out.
func IsReadmeFile(name, mode string) bool {
	if !readmePattern.MatchString(name) {
		return false
	}
	m, err := filemode.New(mode)
	if err != nil {
		return false
	}
	return m == filemode.Regular || m == filemode.Executable
}