diff --git a/src/components/GitSyncProvider.tsx b/src/components/GitSyncProvider.tsx index 73839347..528c1ef0 100644 --- a/src/components/GitSyncProvider.tsx +++ b/src/components/GitSyncProvider.tsx @@ -148,12 +148,14 @@ export function GitSyncProvider({ children }: { children: ReactNode }) { // Git operation: sync (pull then push) const sync = useCallback(async (dir: string, ref: string, remote = 'origin'): Promise => { return withOperationLock(dir, 'pull', async () => { + const cache = {}; + // Pull first - await git.pull({ dir, ref, singleBranch: true }); + await git.pull({ dir, ref, singleBranch: true, cache }); // Then push (update operation type) startOperation(dir, 'push'); - await git.push({ dir, remote, ref }); + await git.push({ dir, remote, ref, cache }); invalidateGitStatus(dir); }); @@ -162,12 +164,15 @@ export function GitSyncProvider({ children }: { children: ReactNode }) { // Git operation: force pull const forcePull = useCallback(async (dir: string, ref: string, remote = 'origin'): Promise => { return withOperationLock(dir, 'pull', async () => { + const cache = {}; + // Step 1: Fetch latest changes from remote await git.fetch({ dir, remote, ref, singleBranch: true, + cache, }); // Step 2: Get the remote commit SHA @@ -187,6 +192,7 @@ export function GitSyncProvider({ children }: { children: ReactNode }) { dir, ref, force: true, + cache, }); invalidateGitStatus(dir); diff --git a/src/lib/git.ts b/src/lib/git.ts index c98e3d19..12a09386 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -95,7 +95,10 @@ export class Git { if (options.url.startsWith('nostr://')) { const nostrURI = await NostrURI.parse(options.url); // Try cloning from Nostr - return this.nostrClone(nostrURI, options); + return this.nostrClone(nostrURI, { + ...options, + cache: options.cache || {}, + }); } // Regular Git URL @@ -248,7 +251,12 @@ export class Git { if (remoteUrl && remoteUrl.startsWith('nostr://')) { const nostrURI = await NostrURI.parse(remoteUrl); - return this.nostrFetch(nostrURI, { ...options, remote, dir }); + return this.nostrFetch(nostrURI, { + ...options, + cache: options.cache || {}, + remote, + dir, + }); } // Regular Git fetch @@ -270,7 +278,13 @@ export class Git { if (remoteUrl && remoteUrl.startsWith('nostr://')) { const nostrURI = await NostrURI.parse(remoteUrl); - return this.nostrPull(nostrURI, { ...options, author, remote, dir }); + return this.nostrPull(nostrURI, { + ...options, + cache: options.cache || {}, + author, + remote, + dir, + }); } // Regular Git pull @@ -291,7 +305,12 @@ export class Git { if (remoteUrl && remoteUrl.startsWith('nostr://')) { const nostrURI = await NostrURI.parse(remoteUrl); - return this.nostrPush(nostrURI, { ...options, remote, dir: dir }); + return this.nostrPush(nostrURI, { + ...options, + cache: options.cache || {}, + remote, + dir, + }); } return git.push({ @@ -734,6 +753,7 @@ export class Git { dir: options.dir, ref: checkoutRef, remote, // This tells checkout which remote to track + cache: options.cache, }); } @@ -868,6 +888,7 @@ export class Git { ours: ref, theirs: remoteTrackingBranch, author: options.author, + cache: options.cache, }); }