fix: ensure git remote origin is set when backup repo already exists

When the repo directory already existed from a previous init (e.g.
local-only init without remote), the origin remote was missing. Now
initRepo() verifies and sets/updates the remote on every startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michal
2026-03-08 14:46:16 +00:00
parent af4b3fb702
commit 6ddc49569a

View File

@@ -394,6 +394,18 @@ export class GitBackupService {
private async initRepo(): Promise<void> { private async initRepo(): Promise<void> {
try { try {
await access(join(REPO_DIR, '.git')); await access(join(REPO_DIR, '.git'));
// Repo exists — ensure remote origin is correct
try {
const { stdout: currentUrl } = await execFile('git', ['remote', 'get-url', 'origin'], { cwd: REPO_DIR });
if (currentUrl.trim() !== this.repoUrl) {
await execFile('git', ['remote', 'set-url', 'origin', this.repoUrl!], { cwd: REPO_DIR });
console.log(`[git-backup] Updated remote origin to ${this.repoUrl}`);
}
} catch {
// No remote — add it
await execFile('git', ['remote', 'add', 'origin', this.repoUrl!], { cwd: REPO_DIR });
console.log(`[git-backup] Added remote origin: ${this.repoUrl}`);
}
console.log('[git-backup] Repo already cloned'); console.log('[git-backup] Repo already cloned');
return; return;
} catch { } catch {