mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add isomorphic-git cache support
https://isomorphic-git.org/docs/en/cache
This commit is contained in:
2 files changed
+33
-6
No files matched your search
@@ -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
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user