mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Move git sync operations directly into GitSyncProvider
This commit is contained in:
4 files changed
+196
-138
No files matched your search
@@ -1,8 +1,15 @@
|
|||||||
import { useState, useCallback, ReactNode } from 'react';
|
import { useState, useCallback, ReactNode, useRef } from 'react';
|
||||||
import { GitSyncContext, GitOperation, GitSyncState } from '@/contexts/GitSyncContext';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { GitSyncContext, GitOperation, GitSyncState, FetchResult } from '@/contexts/GitSyncContext';
|
||||||
|
import { useGit } from '@/hooks/useGit';
|
||||||
|
|
||||||
export function GitSyncProvider({ children }: { children: ReactNode }) {
|
export function GitSyncProvider({ children }: { children: ReactNode }) {
|
||||||
const [syncStates, setSyncStates] = useState<Map<string, GitSyncState>>(new Map());
|
const [syncStates, setSyncStates] = useState<Map<string, GitSyncState>>(new Map());
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { git } = useGit();
|
||||||
|
|
||||||
|
// Track active operations to prevent concurrent operations on the same directory
|
||||||
|
const activeOperations = useRef<Map<string, Promise<unknown>>>(new Map());
|
||||||
|
|
||||||
const startOperation = useCallback((dir: string, operation: GitOperation) => {
|
const startOperation = useCallback((dir: string, operation: GitOperation) => {
|
||||||
setSyncStates(prev => {
|
setSyncStates(prev => {
|
||||||
@@ -68,8 +75,147 @@ export function GitSyncProvider({ children }: { children: ReactNode }) {
|
|||||||
return syncStates.get(dir)?.error;
|
return syncStates.get(dir)?.error;
|
||||||
}, [syncStates]);
|
}, [syncStates]);
|
||||||
|
|
||||||
|
// Helper to invalidate git status queries
|
||||||
|
const invalidateGitStatus = useCallback((dir: string) => {
|
||||||
|
const projectId = dir.split('/').pop();
|
||||||
|
if (projectId) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['git-status', projectId] });
|
||||||
|
}
|
||||||
|
}, [queryClient]);
|
||||||
|
|
||||||
|
// Helper to ensure only one operation runs at a time per directory
|
||||||
|
const withOperationLock = useCallback(async <T,>(
|
||||||
|
dir: string,
|
||||||
|
operation: GitOperation,
|
||||||
|
fn: () => Promise<T>
|
||||||
|
): Promise<T> => {
|
||||||
|
// Check if there's already an active operation for this directory
|
||||||
|
const existingOp = activeOperations.current.get(dir);
|
||||||
|
if (existingOp) {
|
||||||
|
// Wait for the existing operation to complete first
|
||||||
|
await existingOp.catch(() => {
|
||||||
|
// Ignore errors from previous operation
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the new operation
|
||||||
|
startOperation(dir, operation);
|
||||||
|
setError(dir, null);
|
||||||
|
|
||||||
|
const promise = fn()
|
||||||
|
.then(result => {
|
||||||
|
endOperation(dir);
|
||||||
|
activeOperations.current.delete(dir);
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
const error = err instanceof Error ? err : new Error(`${operation} failed`);
|
||||||
|
endOperation(dir, error);
|
||||||
|
setError(dir, error);
|
||||||
|
activeOperations.current.delete(dir);
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
|
||||||
|
activeOperations.current.set(dir, promise);
|
||||||
|
return promise;
|
||||||
|
}, [startOperation, endOperation, setError]);
|
||||||
|
|
||||||
|
// Git operation: fetch
|
||||||
|
const fetch = useCallback(async (dir: string, remote = 'origin'): Promise<FetchResult> => {
|
||||||
|
return withOperationLock(dir, 'fetch', async () => {
|
||||||
|
const fetchResult = await git.fetch({ dir, remote });
|
||||||
|
invalidateGitStatus(dir);
|
||||||
|
return fetchResult;
|
||||||
|
});
|
||||||
|
}, [git, withOperationLock, invalidateGitStatus]);
|
||||||
|
|
||||||
|
// Git operation: pull
|
||||||
|
const pull = useCallback(async (dir: string, ref: string, _remote = 'origin'): Promise<void> => {
|
||||||
|
return withOperationLock(dir, 'pull', async () => {
|
||||||
|
await git.pull({ dir, ref, singleBranch: true });
|
||||||
|
invalidateGitStatus(dir);
|
||||||
|
});
|
||||||
|
}, [git, withOperationLock, invalidateGitStatus]);
|
||||||
|
|
||||||
|
// Git operation: push
|
||||||
|
const push = useCallback(async (dir: string, ref: string, remote = 'origin', force = false): Promise<void> => {
|
||||||
|
return withOperationLock(dir, 'push', async () => {
|
||||||
|
await git.push({ dir, remote, ref, force });
|
||||||
|
invalidateGitStatus(dir);
|
||||||
|
});
|
||||||
|
}, [git, withOperationLock, invalidateGitStatus]);
|
||||||
|
|
||||||
|
// Git operation: sync (pull then push)
|
||||||
|
const sync = useCallback(async (dir: string, ref: string, remote = 'origin'): Promise<void> => {
|
||||||
|
return withOperationLock(dir, 'pull', async () => {
|
||||||
|
// Pull first
|
||||||
|
await git.pull({ dir, ref, singleBranch: true });
|
||||||
|
|
||||||
|
// Then push (update operation type)
|
||||||
|
startOperation(dir, 'push');
|
||||||
|
await git.push({ dir, remote, ref });
|
||||||
|
|
||||||
|
invalidateGitStatus(dir);
|
||||||
|
});
|
||||||
|
}, [git, withOperationLock, invalidateGitStatus, startOperation]);
|
||||||
|
|
||||||
|
// Git operation: force pull
|
||||||
|
const forcePull = useCallback(async (dir: string, ref: string, remote = 'origin'): Promise<void> => {
|
||||||
|
return withOperationLock(dir, 'pull', async () => {
|
||||||
|
// Step 1: Fetch latest changes from remote
|
||||||
|
await git.fetch({
|
||||||
|
dir,
|
||||||
|
remote,
|
||||||
|
ref,
|
||||||
|
singleBranch: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Step 2: Get the remote commit SHA
|
||||||
|
const remoteRef = `refs/remotes/${remote}/${ref}`;
|
||||||
|
const remoteSha = await git.resolveRef({ dir, ref: remoteRef });
|
||||||
|
|
||||||
|
// Step 3: Force update the current branch to point to remote
|
||||||
|
await git.writeRef({
|
||||||
|
dir,
|
||||||
|
ref: `refs/heads/${ref}`,
|
||||||
|
value: remoteSha,
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Step 4: Force checkout all files (overwrite local changes)
|
||||||
|
await git.checkout({
|
||||||
|
dir,
|
||||||
|
ref,
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
invalidateGitStatus(dir);
|
||||||
|
});
|
||||||
|
}, [git, withOperationLock, invalidateGitStatus]);
|
||||||
|
|
||||||
|
// Git operation: force push
|
||||||
|
const forcePush = useCallback(async (dir: string, ref: string, remote = 'origin'): Promise<void> => {
|
||||||
|
return withOperationLock(dir, 'push', async () => {
|
||||||
|
await git.push({ dir, remote, ref, force: true });
|
||||||
|
invalidateGitStatus(dir);
|
||||||
|
});
|
||||||
|
}, [git, withOperationLock, invalidateGitStatus]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GitSyncContext.Provider value={{ syncStates, startOperation, endOperation, setError, getState, getError }}>
|
<GitSyncContext.Provider value={{
|
||||||
|
syncStates,
|
||||||
|
getState,
|
||||||
|
getError,
|
||||||
|
fetch,
|
||||||
|
pull,
|
||||||
|
push,
|
||||||
|
sync,
|
||||||
|
forcePull,
|
||||||
|
forcePush,
|
||||||
|
startOperation,
|
||||||
|
endOperation,
|
||||||
|
setError,
|
||||||
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</GitSyncContext.Provider>
|
</GitSyncContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
|
|||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
const { projectsPath } = useFSPaths();
|
const { projectsPath } = useFSPaths();
|
||||||
const { config } = useAppContext();
|
const { config } = useAppContext();
|
||||||
const { getState, getError, startOperation, endOperation, setError: setGlobalError } = useGitSyncState();
|
const gitSync = useGitSyncState();
|
||||||
|
|
||||||
const dir = `${projectsPath}/${projectId}`;
|
const dir = `${projectsPath}/${projectId}`;
|
||||||
const ref = gitStatus?.currentBranch || 'main';
|
const ref = gitStatus?.currentBranch || 'main';
|
||||||
@@ -54,30 +54,26 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
|
|||||||
const { autosync, isLoading: isLoadingAutosync, setAutosync } = useGitAutosync(dir);
|
const { autosync, isLoading: isLoadingAutosync, setAutosync } = useGitAutosync(dir);
|
||||||
|
|
||||||
// Get unified sync state and error
|
// Get unified sync state and error
|
||||||
const syncState = getState(dir);
|
const syncState = gitSync.getState(dir);
|
||||||
const isSyncing = syncState?.isActive || false;
|
const isSyncing = syncState?.isActive || false;
|
||||||
const currentOperation = syncState?.operation || null;
|
const currentOperation = syncState?.operation || null;
|
||||||
const error = getError(dir) || null;
|
const error = gitSync.getError(dir) || null;
|
||||||
|
|
||||||
// Helper to set error for this directory
|
|
||||||
const setError = useCallback((err: Error | null) => {
|
|
||||||
setGlobalError(dir, err);
|
|
||||||
}, [dir, setGlobalError]);
|
|
||||||
|
|
||||||
const hasRemoteChanges = gitStatus?.remoteBranchExists && ((gitStatus?.ahead ?? 0) > 0 || (gitStatus?.behind ?? 0) > 0);
|
const hasRemoteChanges = gitStatus?.remoteBranchExists && ((gitStatus?.ahead ?? 0) > 0 || (gitStatus?.behind ?? 0) > 0);
|
||||||
const commitsAhead = gitStatus?.ahead ?? 0;
|
const commitsAhead = gitStatus?.ahead ?? 0;
|
||||||
const commitsBehind = gitStatus?.behind ?? 0;
|
const commitsBehind = gitStatus?.behind ?? 0;
|
||||||
|
|
||||||
// Generic git operation handler
|
// Helper to set error for this directory
|
||||||
|
const setError = useCallback((err: Error | null) => {
|
||||||
|
gitSync.setError(dir, err);
|
||||||
|
}, [dir, gitSync]);
|
||||||
|
|
||||||
|
// Generic git operation handler with success feedback
|
||||||
const executeGitOperation = useCallback(async (
|
const executeGitOperation = useCallback(async (
|
||||||
operation: 'pull' | 'push' | 'force-pull' | 'force-push',
|
|
||||||
action: () => Promise<void>
|
action: () => Promise<void>
|
||||||
) => {
|
) => {
|
||||||
if (!remoteUrl) return;
|
if (!remoteUrl) return;
|
||||||
|
|
||||||
const gitOp = operation === 'force-pull' ? 'pull' : operation === 'force-push' ? 'push' : operation;
|
|
||||||
|
|
||||||
startOperation(dir, gitOp);
|
|
||||||
setError(null);
|
setError(null);
|
||||||
setSyncSuccess(false);
|
setSyncSuccess(false);
|
||||||
|
|
||||||
@@ -87,98 +83,30 @@ export function SyncStep({ projectId, remoteUrl }: SyncStepProps) {
|
|||||||
// Show success feedback
|
// Show success feedback
|
||||||
setSyncSuccess(true);
|
setSyncSuccess(true);
|
||||||
setTimeout(() => setSyncSuccess(false), 2500);
|
setTimeout(() => setSyncSuccess(false), 2500);
|
||||||
|
|
||||||
// Clear error on success
|
|
||||||
endOperation(dir);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
const message = err instanceof Error ? err : new Error(`Failed to ${operation}`);
|
// Error is already set by the provider
|
||||||
endOperation(dir, message);
|
|
||||||
setError(message);
|
|
||||||
}
|
}
|
||||||
|
}, [remoteUrl, setError]);
|
||||||
// Invalidate git status to refresh UI
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['git-status', projectId] });
|
|
||||||
}, [projectId, queryClient, remoteUrl, dir, startOperation, endOperation, setError]);
|
|
||||||
|
|
||||||
const handleSync = async () => {
|
const handleSync = async () => {
|
||||||
if (!remoteUrl) return;
|
await executeGitOperation(() => gitSync.sync(dir, ref));
|
||||||
|
|
||||||
setError(null);
|
|
||||||
setSyncSuccess(false);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Pull first to get latest changes
|
|
||||||
startOperation(dir, 'pull');
|
|
||||||
await git.pull({ dir, ref, singleBranch: true });
|
|
||||||
endOperation(dir);
|
|
||||||
|
|
||||||
// Then push local changes
|
|
||||||
startOperation(dir, 'push');
|
|
||||||
await git.push({ dir, remote: 'origin', ref });
|
|
||||||
endOperation(dir);
|
|
||||||
|
|
||||||
// Show success feedback
|
|
||||||
setSyncSuccess(true);
|
|
||||||
setTimeout(() => setSyncSuccess(false), 2500);
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(err);
|
|
||||||
const message = err instanceof Error ? err : new Error('Failed to sync');
|
|
||||||
endOperation(dir, message);
|
|
||||||
setError(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invalidate git status to refresh UI
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['git-status', projectId] });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePull = async () => {
|
const handlePull = async () => {
|
||||||
await executeGitOperation('pull', async () => {
|
await executeGitOperation(() => gitSync.pull(dir, ref));
|
||||||
await git.pull({ dir, ref, singleBranch: true });
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePush = async () => {
|
const handlePush = async () => {
|
||||||
await executeGitOperation('push', async () => {
|
await executeGitOperation(() => gitSync.push(dir, ref));
|
||||||
await git.push({ dir, remote: 'origin', ref });
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleForcePull = async () => {
|
const handleForcePull = async () => {
|
||||||
await executeGitOperation('force-pull', async () => {
|
await executeGitOperation(() => gitSync.forcePull(dir, ref));
|
||||||
// Step 1: Fetch latest changes from remote
|
|
||||||
await git.fetch({
|
|
||||||
dir,
|
|
||||||
remote: 'origin',
|
|
||||||
ref,
|
|
||||||
singleBranch: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Step 2: Get the remote commit SHA
|
|
||||||
const remoteRef = `refs/remotes/origin/${ref}`;
|
|
||||||
const remoteSha = await git.resolveRef({ dir, ref: remoteRef });
|
|
||||||
|
|
||||||
// Step 3: Force update the current branch to point to remote
|
|
||||||
await git.writeRef({
|
|
||||||
dir,
|
|
||||||
ref: `refs/heads/${ref}`,
|
|
||||||
value: remoteSha,
|
|
||||||
force: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Step 4: Force checkout all files (overwrite local changes)
|
|
||||||
await git.checkout({
|
|
||||||
dir,
|
|
||||||
ref,
|
|
||||||
force: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleForcePush = async () => {
|
const handleForcePush = async () => {
|
||||||
await executeGitOperation('force-push', async () => {
|
await executeGitOperation(() => gitSync.forcePush(dir, ref));
|
||||||
await git.push({ dir, remote: 'origin', ref, force: true });
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Temporary feedback state helper
|
// Temporary feedback state helper
|
||||||
|
|||||||
@@ -9,13 +9,30 @@ export interface GitSyncState {
|
|||||||
error?: Error;
|
error?: Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FetchResult {
|
||||||
|
defaultBranch: string | null;
|
||||||
|
fetchHead: string | null;
|
||||||
|
fetchHeadDescription: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GitSyncContextValue {
|
export interface GitSyncContextValue {
|
||||||
|
// State access
|
||||||
syncStates: Map<string, GitSyncState>;
|
syncStates: Map<string, GitSyncState>;
|
||||||
|
getState: (dir: string) => GitSyncState | undefined;
|
||||||
|
getError: (dir: string) => Error | undefined;
|
||||||
|
|
||||||
|
// Git operations
|
||||||
|
fetch: (dir: string, remote?: string) => Promise<FetchResult>;
|
||||||
|
pull: (dir: string, ref: string, remote?: string) => Promise<void>;
|
||||||
|
push: (dir: string, ref: string, remote?: string, force?: boolean) => Promise<void>;
|
||||||
|
sync: (dir: string, ref: string, remote?: string) => Promise<void>;
|
||||||
|
forcePull: (dir: string, ref: string, remote?: string) => Promise<void>;
|
||||||
|
forcePush: (dir: string, ref: string, remote?: string) => Promise<void>;
|
||||||
|
|
||||||
|
// Internal state management (for backward compatibility during migration)
|
||||||
startOperation: (dir: string, operation: GitOperation) => void;
|
startOperation: (dir: string, operation: GitOperation) => void;
|
||||||
endOperation: (dir: string, error?: Error) => void;
|
endOperation: (dir: string, error?: Error) => void;
|
||||||
setError: (dir: string, error: Error | null) => void;
|
setError: (dir: string, error: Error | null) => void;
|
||||||
getState: (dir: string) => GitSyncState | undefined;
|
|
||||||
getError: (dir: string) => Error | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GitSyncContext = createContext<GitSyncContextValue | null>(null);
|
export const GitSyncContext = createContext<GitSyncContextValue | null>(null);
|
||||||
+12
-45
@@ -1,4 +1,4 @@
|
|||||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useGit } from './useGit';
|
import { useGit } from './useGit';
|
||||||
import { useGitSyncState } from './useGitSyncState';
|
import { useGitSyncState } from './useGitSyncState';
|
||||||
import { useProjectSessionStatus } from './useProjectSessionStatus';
|
import { useProjectSessionStatus } from './useProjectSessionStatus';
|
||||||
@@ -13,8 +13,7 @@ interface GitSyncResult {
|
|||||||
|
|
||||||
export function useGitSync(dir: string | undefined, remote = 'origin') {
|
export function useGitSync(dir: string | undefined, remote = 'origin') {
|
||||||
const { git } = useGit();
|
const { git } = useGit();
|
||||||
const queryClient = useQueryClient();
|
const gitSync = useGitSyncState();
|
||||||
const { startOperation, endOperation, setError } = useGitSyncState();
|
|
||||||
|
|
||||||
// Extract project ID from directory path
|
// Extract project ID from directory path
|
||||||
const projectId = dir?.split('/').pop() || '';
|
const projectId = dir?.split('/').pop() || '';
|
||||||
@@ -50,12 +49,7 @@ export function useGitSync(dir: string | undefined, remote = 'origin') {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Always fetch to update remote tracking
|
// Always fetch to update remote tracking
|
||||||
startOperation(dir, 'fetch');
|
const fetchResult = await gitSync.fetch(dir, remote);
|
||||||
const fetchResult = await git.fetch({
|
|
||||||
dir,
|
|
||||||
remote,
|
|
||||||
});
|
|
||||||
endOperation(dir);
|
|
||||||
|
|
||||||
let didPull = false;
|
let didPull = false;
|
||||||
let didPush = false;
|
let didPush = false;
|
||||||
@@ -69,55 +63,30 @@ export function useGitSync(dir: string | undefined, remote = 'origin') {
|
|||||||
if (currentBranch) {
|
if (currentBranch) {
|
||||||
// Pull changes from remote
|
// Pull changes from remote
|
||||||
try {
|
try {
|
||||||
startOperation(dir, 'pull');
|
await gitSync.pull(dir, currentBranch, remote);
|
||||||
await git.pull({
|
|
||||||
dir,
|
|
||||||
ref: currentBranch,
|
|
||||||
singleBranch: true,
|
|
||||||
});
|
|
||||||
didPull = true;
|
didPull = true;
|
||||||
endOperation(dir);
|
// Clear any previous errors on successful pull
|
||||||
|
gitSync.setError(dir, null);
|
||||||
} catch (pullError) {
|
} catch (pullError) {
|
||||||
const error = pullError instanceof Error ? pullError : new Error('Auto-pull failed');
|
|
||||||
endOperation(dir, error);
|
|
||||||
setError(dir, error);
|
|
||||||
// Pull might fail if there are conflicts or diverged branches
|
// Pull might fail if there are conflicts or diverged branches
|
||||||
// Don't throw - just log and continue
|
// Error is already set by the provider - just log and continue
|
||||||
console.warn('Auto-pull failed:', pullError);
|
console.warn('Auto-pull failed:', pullError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push local changes to remote
|
// Push local changes to remote
|
||||||
try {
|
try {
|
||||||
startOperation(dir, 'push');
|
await gitSync.push(dir, currentBranch, remote);
|
||||||
await git.push({
|
|
||||||
dir,
|
|
||||||
remote,
|
|
||||||
ref: currentBranch,
|
|
||||||
});
|
|
||||||
didPush = true;
|
didPush = true;
|
||||||
endOperation(dir);
|
|
||||||
// Clear any previous errors on successful push
|
// Clear any previous errors on successful push
|
||||||
setError(dir, null);
|
gitSync.setError(dir, null);
|
||||||
} catch (pushError) {
|
} catch (pushError) {
|
||||||
const error = pushError instanceof Error ? pushError : new Error('Auto-push failed');
|
|
||||||
endOperation(dir, error);
|
|
||||||
setError(dir, error);
|
|
||||||
// Push might fail if there are conflicts or no changes
|
// Push might fail if there are conflicts or no changes
|
||||||
// Don't throw - just log and continue
|
// Error is already set by the provider - just log and continue
|
||||||
console.warn('Auto-push failed:', pushError);
|
console.warn('Auto-push failed:', pushError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we successfully synced, invalidate git status to refresh UI
|
|
||||||
if (didPull || didPush) {
|
|
||||||
const projectId = dir.split('/').pop();
|
|
||||||
if (projectId) {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['git-status', projectId] });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const err = error instanceof Error ? error : new Error('Auto-sync failed');
|
// Error getting current branch or other unexpected error
|
||||||
setError(dir, err);
|
|
||||||
console.warn('Auto-sync failed:', error);
|
console.warn('Auto-sync failed:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,10 +97,8 @@ export function useGitSync(dir: string | undefined, remote = 'origin') {
|
|||||||
didPush,
|
didPush,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const err = error instanceof Error ? error : new Error('Git sync failed');
|
|
||||||
endOperation(dir, err);
|
|
||||||
setError(dir, err);
|
|
||||||
// Fetch/sync failed, but don't throw - just log and return null
|
// Fetch/sync failed, but don't throw - just log and return null
|
||||||
|
// Error is already set by the provider
|
||||||
console.warn('Git sync failed:', error);
|
console.warn('Git sync failed:', error);
|
||||||
return {
|
return {
|
||||||
defaultBranch: null,
|
defaultBranch: null,
|
||||||
|
|||||||
Reference in new issue
Block a user