Query must return something in useGitFetch

This commit is contained in:
Alex Gleason committed 2025-12-25 00:14:09 -06:00
1 parent 1804436565
commit 2f2957435a
1 file changed
+15 -12
+15 -12
View File
@@ -1,31 +1,34 @@
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { useGit } from './useGit'; import { useGit } from './useGit';
interface GitFetchResult {
defaultBranch: string | null;
fetchHead: string | null;
fetchHeadDescription: string | null;
}
export function useGitFetch(dir: string | undefined) { export function useGitFetch(dir: string | undefined) {
const { git } = useGit(); const { git } = useGit();
const query = useQuery({ const query = useQuery({
queryKey: ['git-fetch', dir], queryKey: ['git-fetch', dir],
queryFn: async (): Promise<void> => { queryFn: async (): Promise<GitFetchResult> => {
if (!dir) { if (dir) {
return;
}
try {
try { try {
await git.fetch({ return await git.fetch({
dir, dir,
}); });
} catch (error) { } catch (error) {
// Fetch failed, but don't throw - just log and return null // Fetch failed, but don't throw - just log and return null
console.warn('Git fetch failed:', error); console.warn('Git fetch failed:', error);
return;
} }
} catch (error) {
console.error('Error during git fetch:', error);
return;
} }
return {
defaultBranch: null,
fetchHead: null,
fetchHeadDescription: null,
};
}, },
enabled: !!dir, enabled: !!dir,
refetchInterval: 60000, // Fetch every 60 seconds refetchInterval: 60000, // Fetch every 60 seconds