-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrs_stat.go
More file actions
68 lines (55 loc) · 1.41 KB
/
grs_stat.go
File metadata and controls
68 lines (55 loc) · 1.41 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package grs
//go:generate stringer -type Dirstat,Branchstat,Indexstat -output grs_stat_strings.go
// Branchstat describes a repo's checked-out branch
type Branchstat int
const (
BRANCH_UNKNOWN Branchstat = iota
BRANCH_UPTODATE
BRANCH_AHEAD
BRANCH_BEHIND
BRANCH_DIVERGED
BRANCH_UNTRACKED
)
// Dirstat describes a repo's directory path
type Dirstat int
const (
GRSDIR_INVALID Dirstat = iota
GRSDIR_VALID
)
// Indexstat describes a repo's Git index
type Indexstat int
const (
INDEX_UNKNOWN Indexstat = iota
INDEX_MODIFIED
INDEX_UNMODIFIED
)
// A GrsStat describes Git repository
type GrsStats struct {
Branch Branchstat // Whether the local repo has diverged
Dir Dirstat // Whether the repo directory is valid
Index Indexstat // Whehter the index of the local repo was modified
CommitTime string // A humand-readable string describing the time of the last commit
}
type GrsStatsOpt func(stats *GrsStats)
func NewGrsStats(options ...GrsStatsOpt) GrsStats {
stats := &GrsStats{}
for _, option := range options {
option(stats)
}
return *stats
}
func WithBranchstat(branchstat Branchstat) GrsStatsOpt {
return func(stats *GrsStats) {
stats.Branch = branchstat
}
}
func WithDirstat(dirstat Dirstat) GrsStatsOpt {
return func(stats *GrsStats) {
stats.Dir = dirstat
}
}
func WithIndexstat(indexstat Indexstat) GrsStatsOpt {
return func(stats *GrsStats) {
stats.Index = indexstat
}
}