adds claude-generated commit messages and a recent commits panel to the git view - adds log tailing in the explorer, branch merging and a clean up button
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import Foundation
|
||||
import HelderServices
|
||||
|
||||
/// Answers `generate` with a scripted message or error and records every prompt.
|
||||
final class FakeCommitMessages: CommitMessageGenerating, @unchecked Sendable {
|
||||
private struct State {
|
||||
var result: Result<String, CommitMessageError> = .success("Adds a generated message")
|
||||
var delay: Duration = .zero
|
||||
var prompts: [String] = []
|
||||
}
|
||||
|
||||
private let state = Locked(State())
|
||||
|
||||
var prompts: [String] { state.current.prompts }
|
||||
|
||||
func setResult(_ result: Result<String, CommitMessageError>) { state.mutate { $0.result = result } }
|
||||
/// How long each `generate` takes before it answers.
|
||||
func setDelay(_ delay: Duration) { state.mutate { $0.delay = delay } }
|
||||
|
||||
func generate(prompt: String) async throws -> String {
|
||||
let (result, delay) = state.mutate { state in
|
||||
state.prompts.append(prompt)
|
||||
return (state.result, state.delay)
|
||||
}
|
||||
if delay > .zero { try await Task.sleep(for: delay) }
|
||||
return try result.get()
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,9 @@ final class FakeGit: GitServicing, @unchecked Sendable {
|
||||
var runsByCommand: [String: FakeGitRun] = [:]
|
||||
var branches = GitBranchList.empty
|
||||
var author: String?
|
||||
var recentCommits: [GitCommitSummary] = []
|
||||
var recentCommitsReads = 0
|
||||
var stagedDiff: StagedDiff? = StagedDiff(stat: " a.txt | 1 +\n", patch: "+a\n")
|
||||
}
|
||||
|
||||
private let state: Locked<State>
|
||||
@@ -54,6 +57,10 @@ final class FakeGit: GitServicing, @unchecked Sendable {
|
||||
func setRun(_ run: FakeGitRun, forCommand command: String) { state.mutate { $0.runsByCommand[command] = run } }
|
||||
func setBranches(_ value: GitBranchList) { state.mutate { $0.branches = value } }
|
||||
func setAuthor(_ value: String?) { state.mutate { $0.author = value } }
|
||||
func setRecentCommits(_ value: [GitCommitSummary]) { state.mutate { $0.recentCommits = value } }
|
||||
var recentCommitsReads: Int { state.current.recentCommitsReads }
|
||||
/// What `stagedDiff` returns; nil plays a failed git read.
|
||||
func setStagedDiff(_ value: StagedDiff?) { state.mutate { $0.stagedDiff = value } }
|
||||
/// Makes every `load` throw this error, or read normally again with nil.
|
||||
func setLoadError(_ error: Error?) { state.mutate { $0.loadError = error } }
|
||||
|
||||
@@ -86,6 +93,13 @@ final class FakeGit: GitServicing, @unchecked Sendable {
|
||||
|
||||
func branches() async -> GitBranchList { state.current.branches }
|
||||
func author() async -> String? { state.current.author }
|
||||
func recentCommits() async -> [GitCommitSummary] {
|
||||
state.mutate { state in
|
||||
state.recentCommitsReads += 1
|
||||
return state.recentCommits
|
||||
}
|
||||
}
|
||||
func stagedDiff() async -> StagedDiff? { state.current.stagedDiff }
|
||||
}
|
||||
|
||||
/// A snapshot with one change per row: (path, status, staged).
|
||||
|
||||
Reference in New Issue
Block a user