@@ -139,30 +139,24 @@ public class GitRepositoryProvider: RepositoryProvider {
139
139
// FIXME: We need infrastructure in this subsystem for reporting
140
140
// status information.
141
141
142
- let process : Process
143
-
144
142
if let cache = setupCacheIfNeeded ( for: repository) {
145
143
// Clone the repository using the cache as a reference if possible.
146
144
// Git objects are not shared (--dissociate) to avoid problems that might occur when the cache is
147
145
// deleted or the package is copied somewhere it cannot reach the cache directory.
148
- process = Process ( args: Git . tool, " clone " , " --reference " , cache. path. pathString, " --dissociate " ,
149
- " --mirror " , repository. url, path. pathString, environment: Git . environment)
150
- } else {
151
- process = Process ( args: Git . tool, " clone " , " --mirror " ,
152
- repository. url, path. pathString, environment: Git . environment)
153
- }
154
-
155
- try processSet? . add ( process)
156
-
157
- try process. launch ( )
158
- let result = try process. waitUntilExit ( )
146
+ let process = Process ( args: Git . tool, " clone " , " --mirror " ,
147
+ cache. path. pathString, path. pathString, environment: Git . environment)
148
+ try processSet? . add ( process)
149
+ try process. checkGitError ( repository: repository)
159
150
160
- // Throw if cloning failed.
161
- guard result. exitStatus == . terminated( code: 0 ) else {
162
- throw GitCloneError (
163
- repository: repository. url,
164
- result: result
165
- )
151
+ let clone = GitRepository ( path: path, isWorkingRepo: false )
152
+ // In destination repo remove the remote which will be pointing to the cached source repo.
153
+ // Set the original remote to the new clone.
154
+ try clone. setURL ( remote: " origin " , url: repository. url)
155
+ } else {
156
+ let process = Process ( args: Git . tool, " clone " , " --mirror " ,
157
+ repository. url, path. pathString, environment: Git . environment)
158
+ try processSet? . add ( process)
159
+ try process. checkGitError ( repository: repository)
166
160
}
167
161
}
168
162
@@ -904,4 +898,22 @@ extension Process {
904
898
}
905
899
return try result. utf8Output ( )
906
900
}
901
+
902
+ /// Execute a git subprocess and get its (UTF-8) output if it has a non zero exit.
903
+ /// - Parameter repository: The repository the process operates on
904
+ /// - Throws: `GitCloneErrorGitCloneError`
905
+ /// - Returns: The process output (stdout + stderr).The process output (stdout + stderr).
906
+ @discardableResult
907
+ public func checkGitError( repository: RepositorySpecifier ) throws -> String {
908
+ try launch ( )
909
+ let result = try waitUntilExit ( )
910
+ // Throw if cloning failed.
911
+ guard result. exitStatus == . terminated( code: 0 ) else {
912
+ throw GitCloneError (
913
+ repository: repository. url,
914
+ result: result
915
+ )
916
+ }
917
+ return try result. utf8Output ( )
918
+ }
907
919
}
0 commit comments