"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const simple_git_1 = tslib_1.__importDefault(require("simple-git"));
const upath_1 = tslib_1.__importDefault(require("upath"));
const global_1 = require("../../../config/global");
const logger_1 = require("../../../logger");
const auth_1 = require("../../../util/git/auth");
async function updateDependency({ fileContent, upgrade, }) {
    const localDir = global_1.GlobalConfig.get('localDir');
    const gitSubmoduleAuthEnvironmentVariables = (0, auth_1.getGitEnvironmentVariables)();
    const gitEnv = {
        // pass all existing env variables
        ...process.env,
        // add all known git Variables
        ...gitSubmoduleAuthEnvironmentVariables,
    };
    const git = (0, simple_git_1.default)(localDir).env(gitEnv);
    const submoduleGit = (0, simple_git_1.default)(upath_1.default.join(localDir, upgrade.depName));
    try {
        await git.submoduleUpdate(['--init', upgrade.depName]);
        await submoduleGit.checkout([upgrade.newDigest]);
        return fileContent;
    }
    catch (err) {
        logger_1.logger.debug({ err }, 'submodule checkout error');
        return null;
    }
}
exports.default = updateDependency;
//# sourceMappingURL=update.js.map