Skip to content

Commit beddc37

Browse files
committed
[SourceControl] Include repository url in the git clone error
<rdar://problem/53228398> (cherry picked from commit 8929db0)
1 parent 39b444c commit beddc37

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

Sources/SPMUtility/StringExtensions.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,11 @@ extension String {
9494
public func spm_dropGitSuffix() -> String {
9595
return spm_dropSuffix(".git")
9696
}
97+
98+
public func spm_multilineIndent(count: Int) -> String {
99+
return self
100+
.split(separator: "\n")
101+
.map{ String(repeating: " ", count: count) + $0 }
102+
.joined(separator: "\n")
103+
}
97104
}

Sources/SourceControl/GitRepository.swift

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ import Basic
1212
import Dispatch
1313
import 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

Comments
 (0)