Add isomorphic-git cache support

https://isomorphic-git.org/docs/en/cache
This commit is contained in:
Alex Gleason committed 2025-12-30 12:40:03 -06:00
1 parent 88def1264d
commit 8fe872e015
2 files changed
+33 -6

No files matched your search

+8 -2
View File
@@ -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<void> => {
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<void> => {
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);
+25 -4
View File
@@ -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,
});
}