@@ -12,8 +12,20 @@ import Basic
1212import Dispatch
1313import SPMUtility
1414
15- public enum GitRepositoryProviderError : Swift . Error {
16- case gitCloneFailure( errorOutput: String )
15+ public struct GitCloneError : Swift . Error , CustomStringConvertible {
16+
17+ /// The repository that was being cloned.
18+ public let repository : String
19+
20+ /// The process result.
21+ public let result : ProcessResult
22+
23+ public var description : String {
24+ let stdout = ( try ? result. utf8Output ( ) ) ?? " "
25+ let stderr = ( try ? result. utf8stderrOutput ( ) ) ?? " "
26+ let output = ( stdout + stderr) . spm_chomp ( ) . spm_multilineIndent ( count: 4 )
27+ return " Failed to clone \( repository) : \n \( output) "
28+ }
1729}
1830
1931/// A `git` repository provider.
@@ -42,14 +54,16 @@ public class GitRepositoryProvider: RepositoryProvider {
4254 args: Git . tool, " clone " , " --mirror " , repository. url, path. pathString, environment: Git . environment)
4355 // Add to process set.
4456 try processSet? . add ( process)
45- // Launch the process.
57+
4658 try process. launch ( )
47- // Block until cloning completes.
4859 let result = try process. waitUntilExit ( )
60+
4961 // Throw if cloning failed.
5062 guard result. exitStatus == . terminated( code: 0 ) else {
51- let errorOutput = try ( result. utf8Output ( ) + result. utf8stderrOutput ( ) ) . spm_chuzzle ( ) ?? " "
52- throw GitRepositoryProviderError . gitCloneFailure ( errorOutput: errorOutput)
63+ throw GitCloneError (
64+ repository: repository. url,
65+ result: result
66+ )
5367 }
5468 }
5569
@@ -700,12 +714,3 @@ private class GitFileSystemView: FileSystem {
700714 throw FileSystemError . unsupported
701715 }
702716}
703-
704- extension GitRepositoryProviderError : CustomStringConvertible {
705- public var description : String {
706- switch self {
707- case . gitCloneFailure( let errorOutput) :
708- return " failed to clone; \( errorOutput) "
709- }
710- }
711- }
0 commit comments