Skip to content

Commit 0d887d4

Browse files
Fix: fresh clone before push to ensure clean state
1 parent acbd0c0 commit 0d887d4

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

demo.html

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,31 @@ <h3>${titleCased}</h3>
618618
}
619619

620620
try {
621-
showSaving('Writing file...');
621+
showSaving('Syncing fresh copy...');
622622

623-
// Write file to IndexedDB filesystem
623+
// Clear and re-clone to ensure clean state
624624
const fs = client.fs;
625625
const dir = client.dir;
626+
const http = createNip98HttpClient(privkey);
627+
628+
// Remove old repo
629+
try {
630+
await fs.promises.rm(dir, { recursive: true });
631+
} catch (e) { /* ignore */ }
632+
await fs.promises.mkdir(dir, { recursive: true });
633+
634+
// Fresh clone
635+
await git.clone({
636+
fs,
637+
http,
638+
dir,
639+
url: REPO,
640+
ref: 'main',
641+
singleBranch: true,
642+
depth: 1
643+
});
644+
645+
showSaving('Writing file...');
626646

627647
await fs.promises.writeFile(`${dir}/${filepath}`, content, 'utf8');
628648

@@ -639,15 +659,12 @@ <h3>${titleCased}</h3>
639659

640660
showSaving('Pushing to server...');
641661

642-
// Push to remote with NIP-98 auth
643-
const http = createNip98HttpClient(privkey);
644662
await git.push({
645663
fs,
646664
http,
647665
dir,
648666
url: REPO,
649-
ref: 'main',
650-
force: true // Force push since we may be editing on stale state
667+
ref: 'main'
651668
});
652669

653670
showSaving('Publishing to Nostr...');

0 commit comments

Comments
 (0)