aboutsummaryrefslogtreecommitdiff
path: root/ref/name/root.go
blob: e37a8fa8815301d9b29e3664282a1b56c90c857d (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package name

import "strings"

// IsPseudo reports whether name is a Git pseudo-ref.
func IsPseudo(name string) bool {
	switch name {
	case "FETCH_HEAD", "MERGE_HEAD":
		return true
	default:
		return false
	}
}

// IsRootSyntax reports whether name matches Git's all-caps root-ref syntax.
func IsRootSyntax(name string) bool {
	for i := range len(name) {
		ch := name[i]
		if (ch < 'A' || ch > 'Z') && ch != '-' && ch != '_' {
			return false
		}
	}

	return true
}

// IsRoot reports whether name is a root ref.
func IsRoot(name string) bool {
	if !IsRootSyntax(name) || IsPseudo(name) {
		return false
	}

	if strings.HasSuffix(name, "_HEAD") {
		return true
	}

	switch name {
	case "HEAD", "AUTO_MERGE", "BISECT_EXPECTED_REV", "NOTES_MERGE_PARTIAL", "NOTES_MERGE_REF", "MERGE_AUTOSTASH":
		return true
	default:
		return false
	}
}