From 068ff7d34bf8b0a41f7502c6303887d670324b95 Mon Sep 17 00:00:00 2001 From: fxliang Date: Wed, 3 Jan 2024 22:35:48 +0800 Subject: [PATCH] feat: m,mirror to set mirror; feat: p,proxy to set proxy; fix: infinite loop when git get head error repeating --- src/rppi_get.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/rppi_get.cpp b/src/rppi_get.cpp index 16fc583..46eab34 100644 --- a/src/rppi_get.cpp +++ b/src/rppi_get.cpp @@ -670,9 +670,18 @@ int main(int argc, char **argv) { "g,git", "install recipe by git repo", cxxopts::value())( "s,search", "search recipe with keyword", cxxopts::value())("c,clean", "clean caches")( - "v,verbose", "verbose settings")("l,list", "list recipes in rppi"); + "v,verbose", "verbose settings")("l,list", "list recipes in rppi")( + "m,mirror", "configure github mirror", cxxopts::value())( + "p,proxy", "configure git proxy", cxxopts::value()); auto result = options.parse(argc, argv); int retry = 0; + if (result.count("mirror")) { + mirror = result["mirror"].as(); + if (mirror.back() != '/') + mirror.append("/"); + } + if (result.count("proxy")) + proxy = result["proxy"].as(); if (result.count("verbose")) { #ifdef _WIN32 std::cout << "mirror: "; @@ -715,7 +724,14 @@ int main(int argc, char **argv) { } else if (result.count("update")) { updaterppi: std::cout << "update rppi index" << std::endl; - update_rppi(cache_dir + "/rppi", mirror, proxy); + int error = update_rppi(cache_dir + "/rppi", mirror, proxy); + retry++; + if (error == GIT_EUNBORNBRANCH) { // get current ref head failed + if (std::filesystem::exists(cache_dir + sep + "rppi")) { + delete_directory(cache_dir + sep + "rppi"); + goto updaterppi; + } + } if (retry > 10) return 0; }