master
1package git
2
3import (
4 "time"
5)
6
7type Ref struct {
8 ref string
9 dirName string
10}
11
12func NewRef(ref string) Ref {
13 return Ref{
14 ref: ref,
15 dirName: RefToFileName(ref),
16 }
17}
18
19func (r Ref) IsEmpty() bool {
20 return r.ref == ""
21}
22
23func (r Ref) String() string {
24 return r.ref
25}
26
27func (r Ref) DirName() string {
28 return r.dirName
29}
30
31type Blob struct {
32 Ref Ref
33 Mode string
34 Path string
35 FileName string
36 Size int64
37}
38
39type Commit struct {
40 Hash string
41 ShortHash string
42 Subject string
43 Body string
44 Author string
45 Email string
46 Date time.Time
47 Parents []string
48 Branch Ref
49 RefNames []RefName
50 Href string
51}
52
53type RefKind string
54
55const (
56 RefKindHEAD RefKind = "HEAD"
57 RefKindRemoteHEAD RefKind = "RemoteHEAD"
58 RefKindBranch RefKind = "Branch"
59 RefKindRemote RefKind = "Remote"
60 RefKindTag RefKind = "Tag"
61)
62
63type RefName struct {
64 Kind RefKind
65 Name string // Name is the primary name of the ref as shown by `git log %D` token (left side for pointers)
66 Target string // Target is set for symbolic refs like "HEAD -> main" or "origin/HEAD -> origin/main"
67}
68
69type Tag struct {
70 Name string
71 Date time.Time
72 ObjectHash string // The hash the tag ref directly points to (tag object for annotated, commit for lightweight)
73 CommitHash string // The peeled commit hash
74}