adds nice git interface

This commit is contained in:
2026-10-30 13:21:45 +01:00
parent b9c03a7637
commit caec81e762
107 changed files with 6466 additions and 3992 deletions
+29 -8
View File
@@ -6,15 +6,36 @@ public enum GitError: Error, Equatable {
case commandFailed(arguments: [String], exitCode: Int32, stderr: String)
}
/// What one `execute` run of git ended with.
public struct GitCommandResult: Sendable, Equatable {
public var exitCode: Int32
public var stdout: String
public var stderr: String
public init(exitCode: Int32, stdout: String, stderr: String) {
self.exitCode = exitCode
self.stdout = stdout
self.stderr = stderr
}
public var succeeded: Bool { exitCode == 0 }
}
public protocol GitServicing: Sendable {
/// The working state, or nil when the project is not a git repository.
func load() async throws -> GitSnapshot?
/// Stages modifications, additions and deletions of the paths.
func stage(_ paths: [String]) async throws
func unstage(_ paths: [String]) async throws
func commit(message: String) async throws
/// Never throws: a failed push is a toast, not an error.
func push() async -> PushResult
/// Reverts each path to HEAD; a file HEAD does not have is unstaged and deleted, and a staged rename gets its source back.
func discard(_ paths: [String]) async throws
/// Runs `git <arguments>` in the project and streams every output line; never throws (a launch failure is exit code -1 with the reason on stderr).
func execute(_ arguments: [String], literalPathspecs: Bool, timeout: TimeInterval?,
onLine: @escaping @Sendable (String, Bool) -> Void) async -> GitCommandResult
/// Local and origin branches.
func branches() async -> GitBranchList
/// `user.name <user.email>` from git config, nil when unset.
func author() async -> String?
}
extension GitServicing {
/// Runs with literal pathspecs and no timeout.
public func execute(_ arguments: [String], onLine: @escaping @Sendable (String, Bool) -> Void) async -> GitCommandResult {
await execute(arguments, literalPathspecs: true, timeout: nil, onLine: onLine)
}
}