diff --git a/include/Frate/System/GitProvider.hpp b/include/Frate/System/GitProvider.hpp index 0c75635..e573304 100644 --- a/include/Frate/System/GitProvider.hpp +++ b/include/Frate/System/GitProvider.hpp @@ -38,6 +38,9 @@ namespace Frate::System { std::vector commits; bool recurse_submodules{false}; bool no_checkout{false}; + bool verbose{false}; + bool remote{false}; + bool init{false}; GitStatus status_result; std::string raw_result; std::string raw_error; @@ -66,6 +69,11 @@ namespace Frate::System { * @return &GitProvider */ GitProvider &push(); + /* + * git submodule update + * @return &GitProvider + */ + GitProvider &submoduleUpdate(); /* * Pull command from git * @return &GitProvider @@ -143,6 +151,10 @@ namespace Frate::System { * @return &GitProvider */ GitProvider &setRecurseSubmodules(bool recurse); + + GitProvider &setVerbose(bool verbose); + GitProvider &setRemote(bool remote); + GitProvider &setInit(bool init); /* * Intended to be chained before other commands * @param no_checkout adds --no-checkout to clone command diff --git a/src/Project/TemplateManager.cpp b/src/Project/TemplateManager.cpp index 5608612..7bc695e 100644 --- a/src/Project/TemplateManager.cpp +++ b/src/Project/TemplateManager.cpp @@ -263,8 +263,17 @@ namespace Frate { Utils::warning << "Template already installed" << std::endl; return template_info; } - - git.checkout(hash); + try { + git.setRecurseSubmodules(true) + .checkout(hash) + .pull() + .setInit(true) + .setRemote(true) + .submoduleUpdate(); + } catch (std::exception &e) { + Utils::error << e.what() << std::endl; + throw std::runtime_error("Failed to checkout template"); + } if (std::filesystem::exists(new_template_path)) { Utils::verbose << "Template already exists at: " << new_template_path @@ -305,7 +314,7 @@ namespace Frate { // Cleanup - std::filesystem::remove_all(tmp_path); + // std::filesystem::remove_all(tmp_path); return template_info; } diff --git a/src/System/Git/GitProvider.cpp b/src/System/Git/GitProvider.cpp index aa12fae..9fb9e18 100644 --- a/src/System/Git/GitProvider.cpp +++ b/src/System/Git/GitProvider.cpp @@ -70,8 +70,6 @@ namespace Frate::System { return *this; } - GitProvider &GitProvider::pull() { return *this; } - GitProvider &GitProvider::clone(std::string url) { if (this->git_url.empty()) { if (url.empty()) { @@ -123,6 +121,50 @@ namespace Frate::System { return *this; } + GitProvider &GitProvider::pull() { + + std::string flags; + + if (this->recurse_submodules) { + flags += " --recurse-submodules "; + } + + Utils::CmdOutput out = Utils::hSystemWithOutput( + work_dir_cmd() + "git pull " + flags + " origin " + this->branch); + + this->raw_result = out.std_out; + this->raw_error = out.std_err; + + if (!this->raw_error.empty()) { + throw GitException(this->raw_error); + } + + return *this; + } + + GitProvider &GitProvider::submoduleUpdate() { + std::string flags; + + if (this->init) { + flags += " --init "; + } + + if (this->remote) { + flags += " --remote "; + } + + Utils::CmdOutput out = Utils::hSystemWithOutput( + work_dir_cmd() + "git submodule update" + flags); + this->raw_result = out.std_out; + this->raw_error = out.std_err; + + if (!this->raw_error.empty()) { + throw GitException(this->raw_error); + } + + return *this; + } + GitProvider &GitProvider::fetch() { Utils::CmdOutput out = Utils::hSystemWithOutput(work_dir_cmd() + "git fetch"); @@ -351,6 +393,21 @@ namespace Frate::System { return *this; } + GitProvider &GitProvider::setVerbose(bool verbose) { + this->verbose = verbose; + return *this; + } + + GitProvider &GitProvider::setRemote(bool remote) { + this->remote = remote; + return *this; + } + + GitProvider &GitProvider::setInit(bool init) { + this->init = init; + return *this; + } + GitProvider &GitProvider::setNoCheckout(bool no_checkout) { this->no_checkout = no_checkout; return *this;