// SPDX-License-Identifier: GPL-2.0-only
/*
 *  ppm/src/cmd/update.c
 *
 *  Fast-forward the registry mirror, then re-run install to refresh
 *  the lockfile against the new commit.
 *
 *  Copyright (C) 2026 Project Tick
 */

#include <ppm/registry.h>

#include <stdio.h>

#include "../cli.h"
#include "../util/log.h"
#include "common.h"

int ppm_cmd_install(int argc, char **argv);

int ppm_cmd_update(int argc, char **argv) {
    (void)argc; (void)argv;

    ppm_registry_t *reg = NULL;
    if (ppm_cmd_open_registry(&reg) != PPM_OK) {
        ppm_error("update: registry not available");
        return 1;
    }
    ppm_error_t err = ppm_registry_fetch(reg);
    ppm_registry_close(reg);
    if (err) {
        ppm_error("update: fetch failed: %s", ppm_strerror(err));
        return 1;
    }

    char *fake_argv[] = { (char *)"install", NULL };
    return ppm_cmd_install(1, fake_argv);
}
