-
Notifications
You must be signed in to change notification settings - Fork 11
/
git_options.go
257 lines (212 loc) · 4.98 KB
/
git_options.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package vcs
import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport"
"golang.org/x/crypto/openpgp"
"strings"
)
type GitOption func(c *GitClient)
func WithPath(path string) GitOption {
return func(c *GitClient) {
c.path = path
}
}
func WithRemoteUrl(url string) GitOption {
return func(c *GitClient) {
c.remoteUrl = url
}
}
func WithIsMem() GitOption {
return func(c *GitClient) {
c.isMem = true
}
}
func WithAuthType(authType GitAuthType) GitOption {
return func(c *GitClient) {
c.authType = authType
}
}
func WithUsername(username string) GitOption {
return func(c *GitClient) {
c.username = username
}
}
func WithPassword(password string) GitOption {
return func(c *GitClient) {
c.password = password
}
}
func WithPrivateKey(key string) GitOption {
return func(c *GitClient) {
c.privateKey = key
}
}
func WithDefaultBranch(branch string) GitOption {
return func(c *GitClient) {
c.defaultBranch = branch
}
}
func WithPrivateKeyPath(path string) GitOption {
return func(c *GitClient) {
c.privateKeyPath = path
}
}
type GitCloneOption func(o *git.CloneOptions)
func WithURL(url string) GitCloneOption {
return func(o *git.CloneOptions) {
o.URL = url
}
}
func WithAuthClone(auth transport.AuthMethod) GitCloneOption {
return func(o *git.CloneOptions) {
o.Auth = auth
}
}
func WithRemoteName(name string) GitCloneOption {
return func(o *git.CloneOptions) {
o.RemoteName = name
}
}
func WithSingleBranch(singleBranch bool) GitCloneOption {
return func(o *git.CloneOptions) {
o.SingleBranch = singleBranch
}
}
func WithNoCheckout(noCheckout bool) GitCloneOption {
return func(o *git.CloneOptions) {
o.NoCheckout = noCheckout
}
}
func WithDepthClone(depth int) GitCloneOption {
return func(o *git.CloneOptions) {
o.Depth = depth
}
}
func WithRecurseSubmodules(recurseSubmodules git.SubmoduleRescursivity) GitCloneOption {
return func(o *git.CloneOptions) {
o.RecurseSubmodules = recurseSubmodules
}
}
func WithTags(tags git.TagMode) GitCloneOption {
return func(o *git.CloneOptions) {
o.Tags = tags
}
}
type GitCheckoutOption func(o *git.CheckoutOptions)
func WithBranch(branch string) GitCheckoutOption {
return func(o *git.CheckoutOptions) {
if strings.HasPrefix(branch, "refs/heads") {
o.Branch = plumbing.ReferenceName(branch)
} else {
o.Branch = plumbing.NewBranchReferenceName(branch)
}
}
}
func WithHash(hash string) GitCheckoutOption {
return func(o *git.CheckoutOptions) {
h := plumbing.NewHash(hash)
if h.IsZero() {
return
}
o.Hash = h
}
}
type GitCommitOption func(o *git.CommitOptions)
func WithAll(all bool) GitCommitOption {
return func(o *git.CommitOptions) {
o.All = all
}
}
func WithAuthor(author *object.Signature) GitCommitOption {
return func(o *git.CommitOptions) {
o.Author = author
}
}
func WithCommitter(committer *object.Signature) GitCommitOption {
return func(o *git.CommitOptions) {
o.Committer = committer
}
}
func WithParents(parents []plumbing.Hash) GitCommitOption {
return func(o *git.CommitOptions) {
o.Parents = parents
}
}
func WithSignKey(signKey *openpgp.Entity) GitCommitOption {
return func(o *git.CommitOptions) {
o.SignKey = signKey
}
}
type GitPullOption func(o *git.PullOptions)
func WithRemoteNamePull(name string) GitPullOption {
return func(o *git.PullOptions) {
o.RemoteName = name
}
}
func WithBranchNamePull(branch string) GitPullOption {
return func(o *git.PullOptions) {
o.ReferenceName = plumbing.NewBranchReferenceName(branch)
}
}
func WithDepthPull(depth int) GitPullOption {
return func(o *git.PullOptions) {
o.Depth = depth
}
}
func WithAuthPull(auth transport.AuthMethod) GitPullOption {
return func(o *git.PullOptions) {
if auth != nil {
o.Auth = auth
}
}
}
func WithRecurseSubmodulesPull(recurseSubmodules git.SubmoduleRescursivity) GitPullOption {
return func(o *git.PullOptions) {
o.RecurseSubmodules = recurseSubmodules
}
}
func WithForcePull(force bool) GitPullOption {
return func(o *git.PullOptions) {
o.Force = force
}
}
type GitPushOption func(o *git.PushOptions)
func WithRemoteNamePush(name string) GitPushOption {
return func(o *git.PushOptions) {
o.RemoteName = name
}
}
func WithRefSpecs(specs []config.RefSpec) GitPushOption {
return func(o *git.PushOptions) {
o.RefSpecs = specs
}
}
func WithAuthPush(auth transport.AuthMethod) GitPushOption {
return func(o *git.PushOptions) {
o.Auth = auth
}
}
func WithPrune(prune bool) GitPushOption {
return func(o *git.PushOptions) {
o.Prune = prune
}
}
func WithForcePush(force bool) GitPushOption {
return func(o *git.PushOptions) {
o.Force = force
}
}
type GitResetOption func(o *git.ResetOptions)
func WithCommit(commit plumbing.Hash) GitResetOption {
return func(o *git.ResetOptions) {
o.Commit = commit
}
}
func WithMode(mode git.ResetMode) GitResetOption {
return func(o *git.ResetOptions) {
o.Mode = mode
}
}