This repository has been archived by the owner on Jun 13, 2022. It is now read-only.
forked from rgburke/grv
/
repo_controller.go
154 lines (125 loc) · 5.22 KB
/
repo_controller.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"errors"
"os"
)
// RefOperationResultHandler is notified when the checkout is complete
type RefOperationResultHandler func(Ref, error)
// RepoResultHandler is notified when a repo operation completes
type RepoResultHandler func(err error)
// CommitResultHandler is notified when commit creation is complete
type CommitResultHandler func(oid *Oid, err error)
const (
checkoutPercentageDiffReportThreshold = 10.0
)
var errReadOnly = errors.New("Invalid operation in read only mode")
// RepoController performs actions on a repository
// and modifies repository state
type RepoController interface {
Initialise(RepoSupplier)
CheckoutRef(Ref, RefOperationResultHandler)
CheckoutCommit(*Commit, RepoResultHandler)
CreateBranch(branchName string, oid *Oid) error
CreateBranchAndCheckout(branchName string, oid *Oid, resultHandler RefOperationResultHandler)
CreateTag(tagName string, oid *Oid) error
CreateAnnotatedTag(tagName string, oid *Oid, resultHandler RefOperationResultHandler)
CheckoutPreviousRef(RefOperationResultHandler)
StageFiles(filePaths []string) error
UnstageFiles(filePaths []string) error
CheckoutFiles(filePaths []string) error
CommitMessageFile() (*os.File, error)
Commit(CommitResultHandler)
AmendCommit(CommitResultHandler)
Pull(remote string, resultHandler RepoResultHandler)
Push(remote string, ref Ref, track bool, resultHandler RepoResultHandler)
DeleteLocalRef(ref Ref) error
DeleteRemoteRef(remote string, ref Ref, resultHandler RepoResultHandler)
MergeRef(Ref) error
Rebase(Ref) error
}
// ReadOnlyRepositoryController does not permit any
// repository modification and returns a read only error
// when such operations are attempted
type ReadOnlyRepositoryController struct{}
// NewReadOnlyRepositoryController creates a new instance
func NewReadOnlyRepositoryController() RepoController {
return &ReadOnlyRepositoryController{}
}
// Initialise does nothing
func (repoController *ReadOnlyRepositoryController) Initialise(RepoSupplier) {}
// CheckoutRef returns a read only error
func (repoController *ReadOnlyRepositoryController) CheckoutRef(ref Ref, resultHandler RefOperationResultHandler) {
go resultHandler(nil, errReadOnly)
}
// CheckoutCommit returns a read only error
func (repoController *ReadOnlyRepositoryController) CheckoutCommit(commit *Commit, resultHandler RepoResultHandler) {
go resultHandler(errReadOnly)
}
// CreateBranch returns a read only error
func (repoController *ReadOnlyRepositoryController) CreateBranch(string, *Oid) error {
return errReadOnly
}
// CreateBranchAndCheckout returns a read only error
func (repoController *ReadOnlyRepositoryController) CreateBranchAndCheckout(branchName string, oid *Oid, resultHandler RefOperationResultHandler) {
go resultHandler(nil, errReadOnly)
}
// CreateTag returns a read only error
func (repoController *ReadOnlyRepositoryController) CreateTag(string, *Oid) error {
return errReadOnly
}
// CreateAnnotatedTag returns a read only error
func (repoController *ReadOnlyRepositoryController) CreateAnnotatedTag(tagName string, oid *Oid, resultHandler RefOperationResultHandler) {
go resultHandler(nil, errReadOnly)
}
// CheckoutPreviousRef returns a read only error
func (repoController *ReadOnlyRepositoryController) CheckoutPreviousRef(resultHandler RefOperationResultHandler) {
go resultHandler(nil, errReadOnly)
}
// StageFiles returns a read only error
func (repoController *ReadOnlyRepositoryController) StageFiles([]string) error {
return errReadOnly
}
// UnstageFiles returns a read only error
func (repoController *ReadOnlyRepositoryController) UnstageFiles([]string) error {
return errReadOnly
}
// CheckoutFiles returns a read only error
func (repoController *ReadOnlyRepositoryController) CheckoutFiles([]string) error {
return errReadOnly
}
// CommitMessageFile returns a read only error
func (repoController *ReadOnlyRepositoryController) CommitMessageFile() (file *os.File, err error) {
return file, errReadOnly
}
// Commit returns a read only error
func (repoController *ReadOnlyRepositoryController) Commit(resultHandler CommitResultHandler) {
go resultHandler(nil, errReadOnly)
}
// AmendCommit returns a read only error
func (repoController *ReadOnlyRepositoryController) AmendCommit(resultHandler CommitResultHandler) {
go resultHandler(nil, errReadOnly)
}
// Pull returns a read only error
func (repoController *ReadOnlyRepositoryController) Pull(remote string, resultHandler RepoResultHandler) {
go resultHandler(errReadOnly)
}
// Push returns a read only error
func (repoController *ReadOnlyRepositoryController) Push(remote string, ref Ref, track bool, resultHandler RepoResultHandler) {
go resultHandler(errReadOnly)
}
// DeleteLocalRef returns a read only error
func (repoController *ReadOnlyRepositoryController) DeleteLocalRef(ref Ref) error {
return errReadOnly
}
// DeleteRemoteRef returns a read only error
func (repoController *ReadOnlyRepositoryController) DeleteRemoteRef(remote string, ref Ref, resultHandler RepoResultHandler) {
go resultHandler(errReadOnly)
}
// MergeRef returns a read only error
func (repoController *ReadOnlyRepositoryController) MergeRef(Ref) error {
return errReadOnly
}
// Rebase returns a read only error
func (repoController *ReadOnlyRepositoryController) Rebase(Ref) error {
return errReadOnly
}