#include "pull.h" #include "args.h" #include "config.h" #include "error.h" #include "log.h" #include "paths.h" #include "url.h" #include "util.h" #include #include #include #include #include #include #include #define _(x) gettext(x) int fetch_progress(const git_indexer_progress *stats, void *data) { bar(stats->indexed_objects, stats->total_objects); return 0; } bool pull_cmd() { if (args.count != 2) { error(_("Please specify a config name or a URL")); return false; } char *repo_url = NULL, *repo_root = NULL; bool ret = false; if (url_is_local(args.list[1])) { repo_root = args.list[1]; goto COPY; } else if (url_is_name(args.list[1])) repo_url = url_complete(args.list[1]); else repo_url = url_ensure_protocol(args.list[1]); rmrf(mc_tmp_path); repo_root = mc_tmp_path; git_libgit2_init(); git_repository *repo = NULL; git_clone_options opts = GIT_CLONE_OPTIONS_INIT; opts.fetch_opts.callbacks.transfer_progress = fetch_progress; opts.fetch_opts.callbacks.payload = NULL; info(_("Cloning %s"), repo_url); bar_init(); if (git_clone(&repo, repo_url, repo_root, NULL) < 0) { const git_error *e = git_error_last(); error(_("Failed to clone the %s: %s"), repo_url, e->message); bar_free(); goto END; } bar_free(); git_libgit2_shutdown(); COPY: if (chdir(repo_root) < 0) { error(_("Failed to chdir to %s"), repo_root); goto END; } config_t repo_cfg; if (!config_load(&repo_cfg, "mc.cfg")) { error(_("Failed to load the configuration file (mc.cfg):")); printf(" %s\n", errch); goto END; } info("Configuration details:"); printf(COLOR_BOLD " Name" COLOR_RESET ": %s\n", repo_cfg.name); printf(COLOR_BOLD " Author" COLOR_RESET ": %s\n", repo_cfg.author); printf(COLOR_BOLD " Keywords" COLOR_RESET ":"); for (int i = 0; i < repo_cfg.keywords.s; i++) printf("%s ", repo_cfg.keywords.c[i]); printf("\n"); END: free(repo_url); return ret; }