Skip to content

Commit bb449b4

Browse files
authored
Workspace: log both branch and revision during checkout (#6470)
This makes it easier to diagnose cases where a stale branch was fetched from source control cache. Currently, no revision is printed when a branch is checked out, which makes it hard to understand which exact revision is stored for that branch in the cache. We have a CI failure, which is likely caused by a stale cache. To confirm this hypothesis, it would be great if exact revision was printed together with a branch when checking out. See current output: ``` Working copy of https://github.com/apple/swift-certificates.git resolved at 0.4.1 Creating working copy for https://github.com/apple/swift-crypto.git Working copy of https://github.com/apple/swift-crypto.git resolved at 2.5.0 Creating working copy for https://github.com/apple/swift-syntax.git Working copy of https://github.com/apple/swift-syntax.git resolved at main ``` There is no way to know which commit of `main` was checked out without having access to this machine. Updated `description` implementation for `CheckoutState` type.
1 parent bdfb9a5 commit bb449b4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Sources/Workspace/CheckoutState.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,21 @@ extension CheckoutState: CustomStringConvertible {
2929
return revision.identifier
3030
case .version(let version, _):
3131
return version.description
32-
case .branch(let branch, _):
33-
return branch
32+
case .branch(let branch, let revision):
33+
return "\(branch) (\(revision.identifier.prefix(7)))"
34+
}
35+
}
36+
}
37+
38+
extension CheckoutState: CustomDebugStringConvertible {
39+
public var debugDescription: String {
40+
switch self {
41+
case .revision(let revision):
42+
return revision.identifier
43+
case .version(let version, let revision):
44+
return "\(version.description) (\(revision.identifier))"
45+
case .branch(let branch, let revision):
46+
return "\(branch) (\(revision.identifier))"
3447
}
3548
}
3649
}

Sources/Workspace/Workspace.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,6 +3329,7 @@ extension Workspace {
33293329
// Inform the delegate that we're done.
33303330
let duration = start.distance(to: .now())
33313331
delegate?.didCheckOut(package: package.identity, repository: repository.location.description, revision: checkoutState.description, at: checkoutPath, duration: duration)
3332+
observabilityScope.emit(debug: "`\(repository.location.description)` checked out at \(checkoutState.debugDescription)")
33323333

33333334
return checkoutPath
33343335
}

0 commit comments

Comments
 (0)