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:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user