Skip to content

Commit

Permalink
fixed the submodule download system in gitprovider and tempalte manager
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Jan 4, 2024
1 parent c37f5c5 commit e39037c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
12 changes: 12 additions & 0 deletions include/Frate/System/GitProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace Frate::System {
std::vector<GitCommit> 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;
Expand Down Expand Up @@ -66,6 +69,11 @@ namespace Frate::System {
* @return &GitProvider
*/
GitProvider &push();
/*
* git submodule update
* @return &GitProvider
*/
GitProvider &submoduleUpdate();
/*
* Pull command from git
* @return &GitProvider
Expand Down Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/Project/TemplateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -305,7 +314,7 @@ namespace Frate {

// Cleanup

std::filesystem::remove_all(tmp_path);
// std::filesystem::remove_all(tmp_path);

return template_info;
}
Expand Down
61 changes: 59 additions & 2 deletions src/System/Git/GitProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e39037c

Please sign in to comment.