(resolvedPath: string)
| 243 | } |
| 244 | |
| 245 | private async inspectResolvedPath(resolvedPath: string): Promise<GitPathInspection> { |
| 246 | const exec = (args: string[]) => this.exec.exec(['-C', resolvedPath, ...args]); |
| 247 | try { |
| 248 | const { stdout } = await exec(['rev-parse', '--is-inside-work-tree']); |
| 249 | if (stdout.trim() !== 'true') return { kind: 'not-repository', path: resolvedPath }; |
| 250 | } catch (error) { |
| 251 | if (isNotRepositoryInspectionError(error)) { |
| 252 | return { kind: 'not-repository', path: resolvedPath }; |
| 253 | } |
| 254 | return { |
| 255 | kind: 'inspect-failed', |
| 256 | path: resolvedPath, |
| 257 | message: gitErrorMessage(error), |
| 258 | }; |
| 259 | } |
| 260 | |
| 261 | let remoteName: string | undefined; |
| 262 | try { |
| 263 | const { stdout } = await exec(['remote']); |
| 264 | const remotes = stdout.trim().split('\n').filter(Boolean); |
| 265 | remoteName = remotes.includes('origin') ? 'origin' : remotes[0]; |
| 266 | } catch {} |
| 267 | |
| 268 | let branch: string | undefined; |
| 269 | try { |
| 270 | const { stdout } = await exec(['branch', '--show-current']); |
| 271 | branch = stdout.trim() || undefined; |
| 272 | } catch {} |
| 273 | |
| 274 | if (!branch && remoteName) { |
| 275 | try { |
| 276 | const { stdout } = await exec(['remote', 'show', remoteName]); |
| 277 | const match = /HEAD branch:\s*(\S+)/.exec(stdout); |
| 278 | branch = match?.[1] ?? undefined; |
| 279 | } catch {} |
| 280 | } |
| 281 | |
| 282 | let rootPath = resolvedPath; |
| 283 | try { |
| 284 | const { stdout } = await exec(['rev-parse', '--show-toplevel']); |
| 285 | const trimmed = stdout.trim(); |
| 286 | if (trimmed) rootPath = realpathOrResolve(trimmed); |
| 287 | } catch {} |
| 288 | |
| 289 | return { |
| 290 | kind: 'repository', |
| 291 | rootPath, |
| 292 | baseRef: computeBaseRef(undefined, remoteName, branch), |
| 293 | }; |
| 294 | } |
| 295 | |
| 296 | private assertOpen(): void { |
| 297 | if (this.disposeRequested) { |
no test coverage detected