Files
helder/Sources/HelderServices/Git/GitServicing.swift
T
2026-10-30 13:21:45 +01:00

42 lines
1.6 KiB
Swift

import Foundation
import HelderCore
public enum GitError: Error, Equatable {
/// A git command exited non-zero; `stderr` is trimmed.
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?
/// 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)
}
}