Skip to content

Commit 171a9d2

Browse files
author
djinni-hppro
committed
.
1 parent da507ab commit 171a9d2

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/git.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,27 @@ _GLOBAL.initGit = async (creds) => {
149149
} catch (e) {}
150150

151151
let isRepo = false;
152+
let remoteUrlChanged = false;
152153
try {
153154
await git.resolveRef({ fs, dir: GIT_DIR, ref: 'HEAD' });
154155
isRepo = true;
156+
157+
// Check if remote URL has changed
158+
try {
159+
const remotes = await git.listRemotes({ fs, dir: GIT_DIR });
160+
const currentRemote = remotes.find(r => r.remote === 'origin');
161+
if (!currentRemote || currentRemote.url !== creds.repoUrl) {
162+
remoteUrlChanged = true;
163+
console.log('GIT: Remote URL changed, reinitializing...');
164+
165+
// Remove old repo and clone fresh
166+
await pfs.rm(GIT_DIR, { recursive: true, force: true });
167+
await pfs.mkdir(GIT_DIR);
168+
isRepo = false;
169+
}
170+
} catch (e) {
171+
console.warn('GIT: Could not check remote URL, continuing:', e);
172+
}
155173
} catch (e) {}
156174

157175
const config = getGitConfig(creds);
@@ -393,7 +411,7 @@ _GLOBAL.finishGitSync = async (creds) => {
393411

394412
} catch (pushErr) {
395413
console.warn('GIT: Push failed, attempting to pull and retry:', pushErr);
396-
414+
397415
try {
398416
// Attempt 2: Pull (Fetch + Merge) then Push
399417
await git.pull({
@@ -402,12 +420,12 @@ _GLOBAL.finishGitSync = async (creds) => {
402420
author: config.author
403421
});
404422
console.log('GIT: Pull successful. Retrying push...');
405-
423+
406424
await git.push(pushOptions);
407425
console.log('GIT: Pushed successfully after merge.');
408426

409427
} catch (retryErr) {
410-
// Attempt 3: Force Push
428+
// Attempt 3: Force Push (final fallback)
411429
console.warn('GIT: Standard push failed after merge. Attempting force push as final fallback:', retryErr);
412430
await git.push({ ...pushOptions, force: true });
413431
console.log('GIT: Force push successful.');

0 commit comments

Comments
 (0)