feat(git): support nested git repositories in the Git tab

When the project root is not itself a git repository, discover nested
repositories (depth- and visit-capped readdir walk via a new
/api/fs/git-dirs route), auto-select the first one, and show a repository
picker next to the branch dropdown to switch. Selections persist per
runtime and root; discovery failure is a distinct marker with a retry
action, never an empty success.
This commit is contained in:
jaygupta17
2026-08-08 19:08:42 +05:30
parent 4faf660a38
commit 9c9c28a552
20 changed files with 989 additions and 191 deletions
+17
View File
@@ -115,6 +115,23 @@ export async function checkIsGitRepository(directory: string): Promise<boolean>
}
}
export async function listGitDirectories(root: string): Promise<string[]> {
const response = await runtimeFetch('/api/fs/git-dirs', { query: { path: root } });
if (!response.ok) {
throw new Error(`Failed to list git directories: ${response.statusText}`);
}
const data = await response.json();
if (!data || !Array.isArray(data.repositories)) {
throw new Error('Unexpected git directories response');
}
return data.repositories
.map((entry: unknown) => {
const path = entry && typeof entry === 'object' && 'path' in entry ? (entry as { path?: unknown }).path : undefined;
return typeof path === 'string' && path.trim() ? path.trim() : null;
})
.filter((path: string | null): path is string => path !== null);
}
export async function getGitStatus(directory: string, options?: { mode?: 'light' }): Promise<GitStatus> {
const mode = options?.mode;
const runtimeKey = getRuntimeKey();