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