-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathEmptyRepoProtocols.swift
303 lines (247 loc) · 8.98 KB
/
EmptyRepoProtocols.swift
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import Foundation
@testable import Xit
/// Empty implementations of all the repository protocols.
/// For these types, "Empty" is used for sub-protocols with default
/// implementations that do nothing. "Null" is for concrete types whose
/// instances represent null or empty values.
protocol EmptyBasicRepository: BasicRepository {}
extension EmptyBasicRepository
{
var controller: (any RepositoryController)? { get { nil } set {} }
}
protocol EmptyBranching: Branching {}
extension EmptyBranching
{
var currentBranch: String? { nil }
var localBranches: AnySequence<any LocalBranch>
{ .init(Array<NullLocalBranch>()) }
var remoteBranches: AnySequence<any RemoteBranch>
{ .init(Array<NullRemoteBranch>()) }
/// Creates a branch at the given target ref
func createBranch(named name: String,
target: String) throws -> (any LocalBranch)? { nil }
func rename(branch: String, to: String) throws {}
func localBranch(named name: String) -> (any LocalBranch)? { nil }
func remoteBranch(named name: String) -> (any RemoteBranch)? { nil }
func localBranch(tracking remoteBranch: any RemoteBranch) -> (any LocalBranch)?
{ nil }
func localTrackingBranch(forBranchRef branch: String) -> (any LocalBranch)?
{ nil }
func reset(toCommit target: any Commit, mode: ResetMode) throws {}
}
class NullLocalBranch: LocalBranch
{
var trackingBranchName: String? { get { nil } set {} }
var trackingBranch: (any RemoteBranch)? { nil }
var name: String { "refs/heads/branch" }
var shortName: String { "branch" }
var oid: (any OID)? { nil }
var targetCommit: (any Commit)? { nil }
}
class NullRemoteBranch: RemoteBranch
{
var name: String { "refs/remotes/origin/branch" }
var shortName: String { "origin/branch" }
var oid: (any OID)? { nil }
var targetCommit: (any Commit)? { nil }
var remoteName: String? { nil }
}
protocol EmptyCommitStorage: CommitStorage {}
extension EmptyCommitStorage
{
func oid(forSHA sha: String) -> ID? { nil }
func commit(forSHA sha: String) -> Commit? { nil }
func commit(forOID oid: ID) -> Commit? { nil }
func commit(message: String, amend: Bool) throws {}
func walker() -> (any RevWalk<ID>)? { nil }
}
protocol EmptyCommitReferencing: CommitReferencing where ID == StringOID {}
extension EmptyCommitReferencing
{
var headRef: String? { nil }
var currentBranch: String? { nil }
func oid(forRef: String) -> StringOID? { nil }
func sha(forRef: String) -> String? { nil }
func tags() throws -> [NullTag] { [] }
func graphBetween(localBranch: any LocalBranch,
upstreamBranch: any RemoteBranch) -> (ahead: Int,
behind: Int)?
{ nil }
func localBranch(named name: String) -> (any LocalBranch)? { nil }
func remoteBranch(named name: String, remote: String) -> (any RemoteBranch)?
{ nil }
func reference(named name: String) -> (any Reference)? { nil }
func refs(at oid: StringOID) -> [String] { [] }
func allRefs() -> [String] { [] }
func rebuildRefsIndex() {}
func createCommit(with tree: Tree,
message: String,
parents: [NullCommit],
updatingReference refName: String) throws -> StringOID
{ §"" }
}
class NullCommit: Commit
{
typealias ObjectIdentifier = StringOID
typealias Tree = NullTree
var id: StringOID { §"" }
var parentOIDs: [StringOID] { [] }
var message: String? { nil }
var authorSig: Signature? { nil }
var committerSig: Signature? { nil }
var tree: NullTree? { nil }
var isSigned: Bool { false }
func getTrailers() -> [(String, [String])] { [] }
}
class NullTree: Tree
{
typealias ObjectIdentifier = StringOID
struct Entry: TreeEntry
{
typealias ObjectIdentifier = StringOID
var id: StringOID { §"" }
var type: GitObjectType { .invalid }
var name: String { "" }
var object: (any OIDObject)? { nil }
}
var id: StringOID { §"" }
var count: Int { 0 }
func entry(named: String) -> Entry? { nil }
func entry(path: String) -> Entry? { nil }
func entry(at index: Int) -> Entry? { nil }
}
class NullTag: Tag
{
var name: String = ""
let signature: Signature? = nil
let targetOID: StringOID? = nil
let commit: NullCommit? = nil
let message: String? = nil
let type: TagType = .annotated
let isSigned: Bool = false
}
protocol EmptyFileStatusDetection: FileStatusDetection {}
extension EmptyFileStatusDetection
{
func changes(for oid: any OID, parent parentOID: (any OID)?) -> [FileChange]
{ [] }
func stagedChanges() -> [FileChange] { [] }
func amendingStagedChanges() -> [FileChange] { [] }
func unstagedChanges(showIgnored: Bool,
recurseUntracked: Bool,
useCache: Bool) -> [FileChange] { [] }
func amendingStagedStatus(for path: String) throws -> DeltaStatus
{ .unmodified }
func amendingUnstagedStatus(for path: String) throws -> DeltaStatus
{ .unmodified }
func stagedStatus(for path: String) throws -> DeltaStatus
{ .unmodified }
func unstagedStatus(for path: String) throws -> DeltaStatus
{ .unmodified }
func status(file: String) throws -> (DeltaStatus, DeltaStatus)
{ (.unmodified, .unmodified) }
func isIgnored(path: String) -> Bool { false }
}
protocol EmptyFileDiffing: FileDiffing {}
extension EmptyFileDiffing
{
func diffMaker(forFile file: String,
commitOID: any OID,
parentOID: (any OID)?) -> PatchMaker.PatchResult? { nil }
func stagedDiff(file: String) -> PatchMaker.PatchResult? { nil }
func unstagedDiff(file: String) -> PatchMaker.PatchResult? { nil }
func amendingStagedDiff(file: String) -> PatchMaker.PatchResult? { nil }
func blame(for path: String,
from startOID: (any OID)?,
to endOID: (any OID)?) -> (any Blame)? { nil }
func blame(for path: String,
data fromData: Data?,
to endOID: (any OID)?) -> (any Blame)? { nil }
}
protocol EmptyFileContents: FileContents {}
extension EmptyFileContents
{
var repoURL: URL { .init(fileURLWithPath: "/") }
func isTextFile(_ path: String, context: FileContext) -> Bool { false }
func fileBlob(ref: String, path: String) -> (any Blob)? { nil }
func stagedBlob(file: String) -> (any Blob)? { nil }
func contentsOfFile(path: String, at commit: any Commit) -> Data? { nil }
func contentsOfStagedFile(path: String) -> Data? { nil }
func fileURL(_ file: String) -> URL { .init(fileURLWithPath: "/") }
}
protocol EmptyFileStaging: FileStaging {}
extension EmptyFileStaging
{
var index: (any StagingIndex)? { nil }
func stage(file: String) throws {}
func unstage(file: String) throws {}
func amendStage(file: String) throws {}
func amendUnstage(file: String) throws {}
func revert(file: String) throws {}
func stageAllFiles() throws {}
func unstageAllFiles() throws {}
func patchIndexFile(path: String, hunk: any DiffHunk, stage: Bool) throws {}
}
protocol EmptyStashing: Stashing {}
extension EmptyStashing
{
var stashes: AnyCollection<any Stash> { .init(Array<GitStash>()) }
func stash(index: UInt, message: String?) -> any Stash { NullStash() }
func popStash(index: UInt) throws {}
func applyStash(index: UInt) throws {}
func dropStash(index: UInt) throws {}
func commitForStash(at index: UInt) -> (any Commit)? { nil }
func saveStash(name: String?,
keepIndex: Bool,
includeUntracked: Bool,
includeIgnored: Bool) throws {}
}
protocol EmptyStash: Stash {}
extension EmptyStash
{
var message: String? { nil }
var mainCommit: NullCommit? { nil }
var indexCommit: NullCommit? { nil }
var untrackedCommit: NullCommit? { nil }
func indexChanges() -> [FileChange] { [] }
func workspaceChanges() -> [FileChange] { [] }
func stagedDiffForFile(_ path: String) -> PatchMaker.PatchResult? { nil }
func unstagedDiffForFile(_ path: String) -> PatchMaker.PatchResult? { nil }
}
class NullStash: EmptyStash
{
typealias ID = StringOID
}
protocol EmptyRemoteManagement: RemoteManagement {}
extension EmptyRemoteManagement
{
func remoteNames() -> [String] { [] }
func remote(named name: String) -> (any Remote)? { nil }
func addRemote(named name: String, url: URL) throws {}
func deleteRemote(named name: String) throws {}
}
public protocol EmptyRemoteCommunication: RemoteCommunication {}
extension EmptyRemoteCommunication
{
func push(branches: [any LocalBranch],
remote: any Remote,
callbacks: RemoteCallbacks) throws {}
func fetch(remote: any Remote, options: FetchOptions) throws {}
func pull(branch: any Branch,
remote: any Remote,
options: FetchOptions) throws {}
}
protocol EmptyTagging: Tagging {}
extension EmptyTagging
{
func createTag(name: String, targetOID: any OID, message: String?) throws {}
func createLightweightTag(name: String, targetOID: any OID) throws {}
func deleteTag(name: String) throws {}
}
protocol EmptyWorkspace: Workspace {}
extension EmptyWorkspace
{
func checkOut(branch: String) throws {}
func checkOut(refName: String) throws {}
func checkOut(sha: String) throws {}
}