@@ -35,6 +35,9 @@ public class Workspace {
35
35
/// The checked out path of the dependency on disk, relative to the workspace checkouts path.
36
36
public let subpath : RelativePath
37
37
38
+ /// The current version of the dependency, if known.
39
+ public let currentVersion : Version ?
40
+
38
41
/// The current revision of the dependency.
39
42
///
40
43
/// This should always be a revision corresponding to the version in the
@@ -44,9 +47,10 @@ public class Workspace {
44
47
/// resolved).
45
48
public let currentRevision : Revision
46
49
47
- fileprivate init ( repository: RepositorySpecifier , subpath: RelativePath , currentRevision: Revision ) {
50
+ fileprivate init ( repository: RepositorySpecifier , subpath: RelativePath , currentVersion : Version ? , currentRevision: Revision ) {
48
51
self . repository = repository
49
52
self . subpath = subpath
53
+ self . currentVersion = currentVersion
50
54
self . currentRevision = currentRevision
51
55
}
52
56
@@ -57,18 +61,39 @@ public class Workspace {
57
61
guard case let . dictionary( contents) = data,
58
62
case let . string( repositoryURL) ? = contents [ " repositoryURL " ] ,
59
63
case let . string( subpathString) ? = contents [ " subpath " ] ,
64
+ let currentVersionData = contents [ " currentVersion " ] ,
60
65
case let . string( currentRevisionString) ? = contents [ " currentRevision " ] else {
61
66
return nil
62
67
}
68
+ let currentVersion : Version ?
69
+ switch currentVersionData {
70
+ case . null:
71
+ currentVersion = nil
72
+ case . string( let string) :
73
+ currentVersion = Version ( string)
74
+ if currentVersion == nil {
75
+ return nil
76
+ }
77
+ default :
78
+ return nil
79
+ }
63
80
self . repository = RepositorySpecifier ( url: repositoryURL)
64
81
self . subpath = RelativePath ( subpathString)
82
+ self . currentVersion = currentVersion
65
83
self . currentRevision = Revision ( identifier: currentRevisionString)
66
84
}
67
85
68
86
fileprivate func toJSON( ) -> JSON {
87
+ let currentVersionData : JSON
88
+ if let currentVersion = self . currentVersion {
89
+ currentVersionData = . string( String ( describing: currentVersion) )
90
+ } else {
91
+ currentVersionData = . null
92
+ }
69
93
return . dictionary( [
70
94
" repositoryURL " : . string( repository. url) ,
71
95
" subpath " : . string( subpath. asString) ,
96
+ " currentVersion " : currentVersionData,
72
97
" currentRevision " : . string( currentRevision. identifier) ,
73
98
] )
74
99
}
@@ -187,12 +212,13 @@ public class Workspace {
187
212
/// - Parameters:
188
213
/// - repository: The repository to clone.
189
214
/// - revision: The revision to check out.
215
+ /// - version: The dependency version the repository is being checked out at, if known.
190
216
/// - Returns: The path of the local repository.
191
217
/// - Throws: If the operation could not be satisfied.
192
218
//
193
219
// FIXME: We are probably going to need a delegate interface so we have a
194
220
// mechanism for observing the actions.
195
- func clone( repository: RepositorySpecifier , at revision: Revision ) throws -> AbsolutePath {
221
+ func clone( repository: RepositorySpecifier , at revision: Revision , for version : Version ? = nil ) throws -> AbsolutePath {
196
222
// Get the repository.
197
223
let path = try fetch ( repository: repository)
198
224
@@ -202,7 +228,8 @@ public class Workspace {
202
228
203
229
// Write the state record.
204
230
dependencyMap [ repository] = ManagedDependency (
205
- repository: repository, subpath: path. relative ( to: checkoutsPath) , currentRevision: revision)
231
+ repository: repository, subpath: path. relative ( to: checkoutsPath) ,
232
+ currentVersion: version, currentRevision: revision)
206
233
try saveState ( )
207
234
208
235
return path
@@ -232,9 +259,7 @@ public class Workspace {
232
259
// got this checkout via loading its manifest successfully.
233
260
//
234
261
// FIXME: Nevertheless, we should handle this failure explicitly.
235
- //
236
- // FIXME: We need to have the correct version to pass here.
237
- let manifest : Manifest = try ! manifestLoader. load ( packagePath: checkoutsPath. appending ( managedDependency. subpath) , baseURL: managedDependency. repository. url, version: nil )
262
+ let manifest : Manifest = try ! manifestLoader. load ( packagePath: checkoutsPath. appending ( managedDependency. subpath) , baseURL: managedDependency. repository. url, version: managedDependency. currentVersion)
238
263
239
264
return KeyedPair ( manifest, key: manifest. url)
240
265
}
0 commit comments