Skip to content

Commit e8d26cb

Browse files
committed
Improve the delegate callbacks for when the workspace clones and checks out working directories of repositories. The old callbacks are invoked as fallback for any client that doesn't implement the new ones.
1 parent 0e722c3 commit e8d26cb

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,22 @@ public protocol WorkspaceDelegate: class {
5959
/// The workspace has finished updating and all the dependencies are already up-to-date.
6060
func dependenciesUpToDate()
6161

62-
/// The workspace has started cloning this repository.
62+
/// The workspace is about to clone a repository from the local cache to a working directory.
63+
func willClone(repository url: String, to path: AbsolutePath)
64+
65+
/// The workspace has cloned a repository from the local cache to a working directory. The error indicates whether the operation failed or succeeded.
66+
func didClone(repository url: String, to path: AbsolutePath, error: Diagnostic?)
67+
68+
/// The workspace has started cloning this repository. This callback is marginally deprecated in favor of the willClone/didClone pair.
6369
func cloning(repository: String)
6470

65-
/// The workspace is checking out a repository.
71+
/// The workspace is about to check out a particular revision of a working directory.
72+
func willCheckOut(repository url: String, revision: String, at path: AbsolutePath)
73+
74+
/// The workspace has checked out a particular revision of a working directory. The error indicates whether the operation failed or succeeded.
75+
func didCheckOut(repository url: String, revision: String, at path: AbsolutePath, error: Diagnostic?)
76+
77+
/// The workspace is checking out a repository. This callback is marginally deprecated in favor of the willCheckOut/didCheckOut pair.
6678
func checkingOut(repository: String, atReference reference: String, to path: AbsolutePath)
6779

6880
/// The workspace is removing this repository because it is no longer needed.
@@ -86,6 +98,15 @@ public protocol WorkspaceDelegate: class {
8698
public extension WorkspaceDelegate {
8799
func willLoadManifest(packagePath: AbsolutePath, url: String, version: Version?, packageKind: PackageReference.Kind) {}
88100
func didLoadManifest(packagePath: AbsolutePath, url: String, version: Version?, packageKind: PackageReference.Kind, manifest: Manifest?, diagnostics: [Diagnostic]) {}
101+
func willClone(repository url: String, to path: AbsolutePath) {
102+
cloning(repository: url)
103+
}
104+
func didClone(repository url: String, to path: AbsolutePath, error: Diagnostic?) {}
105+
func cloning(repository: String) {}
106+
func willCheckOut(repository url: String, revision: String, at path: AbsolutePath) {
107+
checkingOut(repository: url, atReference: revision, to: path)
108+
}
109+
func didCheckOut(repository url: String, revision: String, at path: AbsolutePath, error: Diagnostic?) {}
89110
func checkingOut(repository: String, atReference: String, to path: AbsolutePath) {}
90111
func repositoryWillUpdate(_ repository: String) {}
91112
func repositoryDidUpdate(_ repository: String) {}
@@ -2233,8 +2254,9 @@ extension Workspace {
22332254
try fileSystem.removeFileTree(path)
22342255

22352256
// Inform the delegate that we're starting cloning.
2236-
delegate?.cloning(repository: handle.repository.url)
2257+
delegate?.willClone(repository: handle.repository.url, to: path)
22372258
try handle.cloneCheckout(to: path, editable: false)
2259+
delegate?.didClone(repository: handle.repository.url, to: path, error: nil)
22382260

22392261
return path
22402262
}
@@ -2260,7 +2282,7 @@ extension Workspace {
22602282
let workingRepo = try repositoryManager.provider.openCheckout(at: path)
22612283

22622284
// Inform the delegate.
2263-
delegate?.checkingOut(repository: package.repository.url, atReference: checkoutState.description, to: path)
2285+
delegate?.willCheckOut(repository: package.repository.url, revision: checkoutState.description, at: path)
22642286

22652287
// Do mutable-immutable dance because checkout operation modifies the disk state.
22662288
try fileSystem.chmod(.userWritable, path: path, options: [.recursive, .onlyFiles])
@@ -2274,6 +2296,8 @@ extension Workspace {
22742296
checkoutState: checkoutState))
22752297
try state.saveState()
22762298

2299+
delegate?.didCheckOut(repository: package.repository.url, revision: checkoutState.description, at: path, error: nil)
2300+
22772301
return path
22782302
}
22792303

0 commit comments

Comments
 (0)