()
| 39 | const worktreeSession = getCurrentWorktreeSession(); |
| 40 | useEffect(() => { |
| 41 | async function loadChanges() { |
| 42 | let changeLines: string[] = []; |
| 43 | const gitStatus = await execFileNoThrow('git', ['status', '--porcelain']); |
| 44 | if (gitStatus.stdout) { |
| 45 | changeLines = gitStatus.stdout.split('\n').filter(_ => _.trim() !== ''); |
| 46 | setChanges(changeLines); |
| 47 | } |
| 48 | |
| 49 | // Check for commits to eject |
| 50 | if (worktreeSession) { |
| 51 | // Get commits in worktree that are not in original branch |
| 52 | const { |
| 53 | stdout: commitsStr |
| 54 | } = await execFileNoThrow('git', ['rev-list', '--count', `${worktreeSession.originalHeadCommit}..HEAD`]); |
| 55 | const count = parseInt(commitsStr.trim()) || 0; |
| 56 | setCommitCount(count); |
| 57 | |
| 58 | // If no changes and no commits, clean up silently |
| 59 | if (changeLines.length === 0 && count === 0) { |
| 60 | setStatus('removing'); |
| 61 | void cleanupWorktree().then(() => { |
| 62 | process.chdir(worktreeSession.originalCwd); |
| 63 | setCwd(worktreeSession.originalCwd); |
| 64 | recordWorktreeExit(); |
| 65 | getPlansDirectory.cache.clear?.(); |
| 66 | setResultMessage('Worktree removed (no changes)'); |
| 67 | }).catch(error => { |
| 68 | logForDebugging(`Failed to clean up worktree: ${error}`, { |
| 69 | level: 'error' |
| 70 | }); |
| 71 | setResultMessage('Worktree cleanup failed, exiting anyway'); |
| 72 | }).then(() => { |
| 73 | setStatus('done'); |
| 74 | }); |
| 75 | return; |
| 76 | } else { |
| 77 | setStatus('asking'); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | void loadChanges(); |
| 82 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 83 | // biome-ignore lint/correctness/useExhaustiveDependencies: intentional |
no test coverage detected