"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.restoreBaseBranch = restoreBaseBranch;
const native_git_cli_1 = require("../git/native-git-cli");
const catalog_1 = require("../i18n/catalog");
async function restoreBaseBranch(input) {
    try {
        await (0, native_git_cli_1.runNativeGitWithLegacyRunner)(input.run, {
            args: ["switch", input.baseBranch],
            cwd: input.cwd,
            locale: input.locale,
            suppressHooks: true,
        });
        await (0, native_git_cli_1.runNativeGitWithLegacyRunner)(input.run, {
            args: ["fetch", input.remoteName, input.baseBranch],
            cwd: input.cwd,
            locale: input.locale,
            credentials: input.credentials ?? null,
            suppressHooks: true,
        });
        await (0, native_git_cli_1.runNativeGitWithLegacyRunner)(input.run, {
            args: input.preserveLocalChanges
                ? ["merge", "--ff-only", `${input.remoteName}/${input.baseBranch}`]
                : ["reset", "--hard", `${input.remoteName}/${input.baseBranch}`],
            cwd: input.cwd,
            locale: input.locale,
            suppressHooks: true,
        });
    }
    catch (error) {
        console.warn((0, catalog_1.translate)(input.locale, "publish.command.restoreBaseFailed", {
            baseBranch: input.baseBranch,
            message: error instanceof Error ? error.message : String(error),
        }));
    }
}
