fix(git): stop auto-select re-picking a repository that failed its probe

A corrupt nested repository can be discovered (its .git entry exists)
but fail its status probe. The stale-selection recovery cleared the
pick and forced a re-scan, and auto-select immediately re-picked the
same path, looping discovery walk + probe for as long as the surface
stayed visible.

clearNestedRepoSelection now remembers the dropped repository per root
(session-only set, cleared on runtime switch), and auto-select skips
remembered paths. When every candidate has failed, no selection is made
and surfaces settle into their unresolved state instead of churning
requests. A manual picker pick remains possible and is probed like any
other.
This commit is contained in:
jaygupta17
2026-08-26 09:04:50 +05:30
parent d00a48b8b1
commit e7a3d0e38d
4 changed files with 78 additions and 5 deletions
@@ -386,6 +386,30 @@ describe('useGitStore nested repository discovery', () => {
expect(useGitStore.getState().nestedRepoSelection.get('/root-b')).toBe('/root-b/two');
});
test('remembers a stale-cleared repository so auto-select can skip it', () => {
useGitStore.getState().selectNestedRepo('/root-a', '/root-a/one');
useGitStore.getState().selectNestedRepo('/root-b', '/root-b/two');
useGitStore.getState().clearNestedRepoSelection('/root-a');
useGitStore.getState().clearNestedRepoSelection('/root-b');
useGitStore.getState().clearNestedRepoSelection('/root-b');
const clearedA = useGitStore.getState().staleClearedSelections.get('/root-a');
const clearedB = useGitStore.getState().staleClearedSelections.get('/root-b');
expect(clearedA).toEqual(new Set(['/root-a/one']));
// Repeated clears of the same path stay a set, not an ever-growing list.
expect(clearedB).toEqual(new Set(['/root-b/two']));
});
test('runtime switch clears stale-cleared memory with the rest', () => {
useGitStore.getState().selectNestedRepo('/root-a', '/root-a/one');
useGitStore.getState().clearNestedRepoSelection('/root-a');
useGitStore.getState().resetForRuntimeSwitch('runtime-b');
expect(useGitStore.getState().staleClearedSelections.size).toBe(0);
});
test('runtime switch does not leak selections or discovery across runtimes', () => {
useGitStore.getState().selectNestedRepo('/root-a', '/root-a/one');
useGitStore.setState({ nestedReposByRoot: new Map([['/root-a', ['/root-a/one']]]) });