Line data Source code
1 : /*! 2 : * \file esys/repo/cli/cmdsync_cli.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2020-2023 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/cli/cmdsync.h" 20 : #include "esys/repo/githelper.h" 21 : 22 : #include <esys/md/rend/styled_string.h> 23 : 24 : #include <termcolor/termcolor.hpp> 25 : 26 : #include <boost/filesystem.hpp> 27 : 28 : #include <vector> 29 : 30 : namespace esys::repo::cli 31 : { 32 : 33 : #include "esys/repo/cli/cmdsync_doc.cpp" 34 : 35 18 : CmdSync::CmdSync(AppBase *app) 36 36 : : BaseType(app, "sync", "Update working tree to the latest revision") 37 : { 38 18 : } 39 : 40 18 : CmdSync::~CmdSync() = default; 41 : 42 4 : std::shared_ptr<po::options_description> CmdSync::get_desc() 43 : { 44 4 : auto desc = Cmd::get_desc(); 45 4 : if (desc != nullptr) return desc; 46 : 47 4 : desc = std::make_shared<po::options_description>("Sync options"); 48 : // clang-format off 49 4 : desc->add_options() 50 4 : ("force-sync", po::value<bool>()->default_value(false)->implicit_value(true), 51 : "overwrite an existing git directory if it needs to" 52 : "point to a different object directory. WARNING: this" 53 : "may cause loss of data") 54 4 : ("job,j", po::value<int>()->default_value(1), "projects to fetch simultaneously (default 1)") 55 4 : ("groups,g", po::value<std::string>(), "the groups to synchronize") 56 4 : ("branch,b", po::value<std::string>(), "the branch to synchronize across repos") 57 4 : ("rev-set", po::value<std::string>(), "native manifest revision-set name") 58 4 : ("alt,a", "use alternative address for git repos") 59 4 : ("multi,m", "use captured branches for changes spanning multiple repositories") 60 4 : ("tui", "fullscreen Compact RepoSync progress dashboard (TTY; requires FTXUI build)") 61 4 : ("tui-demo", "like --tui, plus a timed on-screen Tab hint (also ESYSREPO_TUI_DEMO=1)") 62 4 : ("phase-timing", "log per-repo GitHelper phase timings (ms); overrides ESYSREPO_SYNC_PHASE_TIMING") 63 4 : ("no-phase-timing", "disable phase timing logs even if ESYSREPO_SYNC_PHASE_TIMING is set") 64 4 : ("recurse-submodules", "also sync Git submodules of each project (ADR-0032)") 65 4 : ("no-recurse-submodules", "do not sync Git submodules even if sync-s is set (ADR-0032)") 66 : ; 67 : // clang-format on 68 8 : Cmd::set_desc(desc); 69 4 : return desc; 70 0 : } 71 : 72 11 : int CmdSync::configure_cmd(CmdType &cmd) 73 : { 74 44 : if (get_vm().count("job")) cmd.set_job_count(get_vm()["job"].as<int>()); 75 11 : cmd.set_sub_args(get_sub_args()); 76 22 : if (get_vm().count("groups")) 77 : { 78 0 : std::vector<std::string> groups; 79 : 80 0 : int result = groups_str_to_groups(get_vm()["groups"].as<std::string>(), groups); 81 0 : if (result < 0) 82 : { 83 0 : return -1; 84 : } 85 0 : cmd.set_groups(groups); 86 0 : } 87 22 : if (get_vm().count("branch")) cmd.set_branch(get_vm()["branch"].as<std::string>()); 88 26 : if (get_vm().count("rev-set")) cmd.set_rev_set(get_vm()["rev-set"].as<std::string>()); 89 23 : if (get_vm()["force-sync"].as<bool>()) cmd.set_force(true); 90 22 : if (get_vm().count("alt")) cmd.set_alt_address(true); 91 22 : if (get_vm().count("multi")) cmd.set_multi(true); 92 22 : if (get_vm().count("tui")) cmd.set_tui(true); 93 22 : if (get_vm().count("tui-demo")) cmd.set_tui_demo(true); 94 22 : if (get_vm().count("phase-timing")) GitHelper::set_phase_timing(true); 95 22 : if (get_vm().count("no-phase-timing")) GitHelper::set_phase_timing(false); 96 : // Prefer --no-recurse-submodules when both flags are present (safer). 97 22 : if (get_vm().count("no-recurse-submodules")) 98 2 : cmd.set_recurse_submodules(manifest::RecurseSubmodules::No); 99 18 : else if (get_vm().count("recurse-submodules")) 100 1 : cmd.set_recurse_submodules(manifest::RecurseSubmodules::Yes); 101 : 102 : return 0; 103 : } 104 : 105 1 : int CmdSync::print_doc(std::ostream &os) 106 : { 107 1 : os << cmdsync_doc_strings; 108 1 : return 0; 109 : } 110 : 111 : } // namespace esys::repo::cli