(
startPath: string,
options?: {
getCloudStatus?: (repoRoot: string) => Promise<string | null>
},
)
| 168 | } |
| 169 | |
| 170 | export async function detectCitcWorkspaceSourceForPath( |
| 171 | startPath: string, |
| 172 | options?: { |
| 173 | getCloudStatus?: (repoRoot: string) => Promise<string | null> |
| 174 | }, |
| 175 | ): Promise<NoumenaWorkspaceSource | null> { |
| 176 | const repoRoot = await findSaplingWorkspaceRoot(startPath) |
| 177 | if (!repoRoot) { |
| 178 | return null |
| 179 | } |
| 180 | |
| 181 | const commitCloudRcPath = await findFirstExistingPath( |
| 182 | repoRoot, |
| 183 | COMMIT_CLOUD_RC_CANDIDATES, |
| 184 | ) |
| 185 | if (!commitCloudRcPath) { |
| 186 | return null |
| 187 | } |
| 188 | |
| 189 | const commitCloudRc = await readTextIfExists(commitCloudRcPath) |
| 190 | if (!commitCloudRc) { |
| 191 | return null |
| 192 | } |
| 193 | |
| 194 | const parsedWorkspace = parseCommitCloudRc(commitCloudRc) |
| 195 | if (!parsedWorkspace) { |
| 196 | return null |
| 197 | } |
| 198 | |
| 199 | const saplingConfigPath = await findFirstExistingPath( |
| 200 | repoRoot, |
| 201 | SAPLING_CONFIG_CANDIDATES, |
| 202 | ) |
| 203 | if (!saplingConfigPath) { |
| 204 | return null |
| 205 | } |
| 206 | |
| 207 | const saplingConfig = await readTextIfExists(saplingConfigPath) |
| 208 | const repo = saplingConfig ? parseSaplingRepoName(saplingConfig) : null |
| 209 | if (!repo) { |
| 210 | return null |
| 211 | } |
| 212 | |
| 213 | let rawWorkspaceName = parsedWorkspace.rawWorkspaceName |
| 214 | let workspaceVersion: number | null = null |
| 215 | let workspaceState: string | null = null |
| 216 | |
| 217 | const cloudStatus = await (options?.getCloudStatus ?? |
| 218 | getCloudStatusViaSapling)(repoRoot) |
| 219 | if (cloudStatus) { |
| 220 | const parsedStatus = parseWorkspaceStatus(cloudStatus) |
| 221 | if ( |
| 222 | parsedStatus.rawWorkspaceName && |
| 223 | parsedStatus.rawWorkspaceName !== rawWorkspaceName |
| 224 | ) { |
| 225 | logForDebugging( |
| 226 | `[citcWorkspaceSource] commitcloudrc workspace ${rawWorkspaceName} disagrees with cloud status ${parsedStatus.rawWorkspaceName}; preferring cloud status`, |
| 227 | ) |
no test coverage detected