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