@@ -1278,6 +1278,23 @@ export class DefaultPackageManager implements PackageManager {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
private async getLocalGitUpdateTarget(installedPath: string): Promise<{ ref: string; head: string }> {
|
||||
try {
|
||||
const head = await this.runCommandCapture("git", ["rev-parse", "@{upstream}"], {
|
||||
cwd: installedPath,
|
||||
timeoutMs: NETWORK_TIMEOUT_MS,
|
||||
});
|
||||
return { ref: "@{upstream}", head };
|
||||
} catch {
|
||||
await this.runCommand("git", ["remote", "set-head", "origin", "-a"], { cwd: installedPath }).catch(() => {});
|
||||
const head = await this.runCommandCapture("git", ["rev-parse", "origin/HEAD"], {
|
||||
cwd: installedPath,
|
||||
timeoutMs: NETWORK_TIMEOUT_MS,
|
||||
});
|
||||
return { ref: "origin/HEAD", head };
|
||||
}
|
||||
}
|
||||
|
||||
private async getGitUpstreamRef(installedPath: string): Promise<string | undefined> {
|
||||
try {
|
||||
const upstream = await this.runCommandCapture("git", ["rev-parse", "--abbrev-ref", "@{upstream}"], {
|
||||
@@ -1463,14 +1480,17 @@ export class DefaultPackageManager implements PackageManager {
|
||||
// Fetch latest from remote (handles force-push by getting new history)
|
||||
await this.runCommand("git", ["fetch", "--prune", "origin"], { cwd: targetDir });
|
||||
|
||||
// Reset to tracking branch. Fall back to origin/HEAD when no upstream is configured.
|
||||
try {
|
||||
await this.runCommand("git", ["reset", "--hard", "@{upstream}"], { cwd: targetDir });
|
||||
} catch {
|
||||
await this.runCommand("git", ["remote", "set-head", "origin", "-a"], { cwd: targetDir }).catch(() => {});
|
||||
await this.runCommand("git", ["reset", "--hard", "origin/HEAD"], { cwd: targetDir });
|
||||
const localHead = await this.runCommandCapture("git", ["rev-parse", "HEAD"], {
|
||||
cwd: targetDir,
|
||||
timeoutMs: NETWORK_TIMEOUT_MS,
|
||||
});
|
||||
const target = await this.getLocalGitUpdateTarget(targetDir);
|
||||
if (localHead.trim() === target.head.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.runCommand("git", ["reset", "--hard", target.ref], { cwd: targetDir });
|
||||
|
||||
// Clean untracked files (extensions should be pristine)
|
||||
await this.runCommand("git", ["clean", "-fdx"], { cwd: targetDir });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user