MCPcopy Index your code
hub / github.com/codeaashu/claude-code / WorktreeExitDialog

Function WorktreeExitDialog

src/components/WorktreeExitDialog.tsx:29–230  ·  view source on GitHub ↗
({
  onDone,
  onCancel
}: Props)

Source from the content-addressed store, hash-verified

27 onCancel?: () => void;
28};
29export function WorktreeExitDialog({
30 onDone,
31 onCancel
32}: Props): React.ReactNode {
33 const [status, setStatus] = useState<'loading' | 'asking' | 'keeping' | 'removing' | 'done'>('loading');
34 const [changes, setChanges] = useState<string[]>([]);
35 const [commitCount, setCommitCount] = useState<number>(0);
36 const [resultMessage, setResultMessage] = useState<string | undefined>();
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
82 }, [worktreeSession]);
83 useEffect(() => {
84 if (status === 'done') {
85 onDone(resultMessage);
86 }

Callers

nothing calls this directly

Calls 3

loadChangesFunction · 0.85
onDoneFunction · 0.50

Tested by

no test coverage detected