()
| 351 | } |
| 352 | |
| 353 | private async start(): Promise<void> { |
| 354 | this.gitDir = await resolveGitDir() |
| 355 | this.initialized = true |
| 356 | if (!this.gitDir) { |
| 357 | return |
| 358 | } |
| 359 | |
| 360 | // In a worktree, branch refs and the main config are shared and live in |
| 361 | // commonDir, not the per-worktree gitDir. Resolve once so we don't |
| 362 | // re-read the commondir file on every branch switch. |
| 363 | this.commonDir = await getCommonDir(this.gitDir) |
| 364 | |
| 365 | // Watch .git/HEAD and .git/config |
| 366 | this.watchPath(join(this.gitDir, 'HEAD'), () => { |
| 367 | void this.onHeadChanged() |
| 368 | }) |
| 369 | // Config (remote URLs) lives in commonDir for worktrees |
| 370 | this.watchPath(join(this.commonDir ?? this.gitDir, 'config'), () => { |
| 371 | this.invalidate() |
| 372 | }) |
| 373 | |
| 374 | // Watch the current branch's ref file for commit changes |
| 375 | await this.watchCurrentBranchRef() |
| 376 | |
| 377 | registerCleanup(async () => { |
| 378 | this.stopWatching() |
| 379 | }) |
| 380 | } |
| 381 | |
| 382 | private watchPath(path: string, callback: () => void): void { |
| 383 | this.watchedPaths.push(path) |
no test coverage detected