Skip to content

Commit

Permalink
fixed tests maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Jan 3, 2024
1 parent 7127953 commit beab83e
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ project (
set(CMAKE_CXX_STANDARD 20)
set(-DUSE_CCACHE=YES -DCCACHE_OPTIONS="CCACHE_CPP2=true;CCACHE_SLOPPINESS=clang_index_store")


find_program(SCCACHE_FOUND sccache)
find_program(CCACHE_FOUND ccache)

Expand Down
2 changes: 2 additions & 0 deletions include/Frate/Project/InstalledTemplate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ namespace Frate::Project {
System::GitCommit &getLatestCommit();
friend void to_json(nlohmann::json &j, const InstalledTemplate &t);
friend void from_json(const nlohmann::json &j, InstalledTemplate &t);
friend std::ostream &operator<<(std::ostream &os_stream,
const InstalledTemplate &temp);
};
} // namespace Frate::Project
7 changes: 7 additions & 0 deletions include/Frate/System/GitProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Frate::System {
std::vector<GitRef> pulls;
std::vector<GitCommit> commits;
bool recurse_submodules{false};
bool no_checkout{false};
GitStatus status_result;
std::string raw_result;
std::string raw_error;
Expand Down Expand Up @@ -142,6 +143,12 @@ namespace Frate::System {
* @return &GitProvider
*/
GitProvider &setRecurseSubmodules(bool recurse);
/*
* Intended to be chained before other commands
* @param no_checkout adds --no-checkout to clone command
* @return &GitProvider
*/
GitProvider &setNoCheckout(bool no_checkout);

const std::vector<GitRef> &getTags() { return tags; };

Expand Down
4 changes: 2 additions & 2 deletions src/Generators/ProjectGenerator/ProjectGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace Frate::Generators::Project {
Utils::info << "Creating project from template: " << templ.name
<< std::endl;
}
Utils::info << "Downloading template at: " << current_template.git
<< std::endl;

std::filesystem::create_directories(inter->pro->path / "override");

TemplateMeta installed_template =
inter->config.templates.install(current_template.name);
Expand Down
16 changes: 14 additions & 2 deletions src/Project/InstalledTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ namespace Frate::Project {
void to_json(nlohmann::json &json_obj,
const InstalledTemplate &template_obj) {
TO_JSON_FIELD(template_obj, name);
TO_JSON_FIELD(template_obj, latest);
TO_JSON_FIELD(template_obj, commits);
TO_JSON_FIELD(template_obj, git);
}

void from_json(const nlohmann::json &json_obj,
InstalledTemplate &template_obj) {
FROM_JSON_FIELD(template_obj, name);
FROM_JSON_FIELD(template_obj, latest);
FROM_JSON_FIELD(template_obj, commits);
FROM_JSON_FIELD(template_obj, git);
}

std::ostream &operator<<(std::ostream &os_stream,
const InstalledTemplate &template_obj) {
os_stream << "Name: " << template_obj.name << std::endl;
os_stream << "Commits: " << std::endl;
for (System::GitCommit commit : template_obj.commits) {
os_stream << commit << std::endl;
}
return os_stream;
}
} // namespace Frate::Project
43 changes: 34 additions & 9 deletions src/Project/TemplateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <Frate/Project/TemplateManager.hpp>
#include <Frate/Utils/Macros.hpp>
#include <filesystem>
#include <variant>

namespace Frate {
using Project::InstalledTemplate;
Expand Down Expand Up @@ -189,6 +188,23 @@ namespace Frate {
throw std::runtime_error("Failed to copy file: " + relative_path);
}
}

if (std::filesystem::exists(override_path)) {
Utils::verbose << "Copying override files from: " << override_path
<< " to " << tmp_gen_path << std::endl;

for (std::filesystem::directory_entry entry :
std::filesystem::recursive_directory_iterator(override_path)) {
std::string relative_path =
entry.path().string().substr(override_path.string().length() + 1);

std::filesystem::path new_file_path = tmp_gen_path / relative_path;

Utils::verbose << "Copying: " << relative_path + " to "
<< new_file_path.string() << std::endl;
}
}
exit(-1);
return tmp_gen_path;
}

Expand Down Expand Up @@ -219,16 +235,12 @@ namespace Frate {
<< std::endl;

try {
git.setRecurseSubmodules(true).clone(template_info.git).log();

if (!hash.empty()) {
git.checkout(hash);
}
git.setNoCheckout(true).clone(template_info.git).log();

} catch (std::exception &e) {
Utils::error << "Failed to clone template: " << name << std::endl;
Utils::error << e.what() << std::endl;
throw std::runtime_error("Failed to clone template");
throw std::runtime_error("Failed to clone template " + name);
}

if (git.getCommits().empty()) {
Expand All @@ -237,16 +249,24 @@ namespace Frate {

System::GitCommit latest_commit = git.getCommits().front();

Utils::info << "Latest commit: " << latest_commit << std::endl;

// appending on the hash to the path so we can have multiple versions
new_template_path /= latest_commit.hash;

template_info.hash = latest_commit.hash;

if (is_installed(name, latest_commit.hash)) {
if (!hash.empty()) {
template_info.hash = hash;
}

if (is_installed(name, template_info.hash)) {
Utils::warning << "Template already installed" << std::endl;
return template_info;
}

git.checkout(hash);

if (std::filesystem::exists(new_template_path)) {
Utils::verbose << "Template already exists at: " << new_template_path
<< " we're going to delete it because we already "
Expand Down Expand Up @@ -275,7 +295,11 @@ namespace Frate {
InstalledTemplate installed_template;
installed_template.name = name;
installed_template.git = template_info.git;
installed_template.commits = git.getCommits();
// We only want to add the latest commit
installed_template.commits.push_back(latest_commit);

Utils::info << "Putting template in config: " << installed_template
<< std::endl;

// Installing the template in the config
installed.push_back(installed_template);
Expand All @@ -297,4 +321,5 @@ namespace Frate {
void to_json(nlohmann::json &json_obj, const TemplateManager &templ) {
TO_JSON_FIELD(templ, installed);
}

} // namespace Frate
17 changes: 14 additions & 3 deletions src/System/Git/GitProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ namespace Frate::System {
flags += " --recurse-submodules ";
}

if (this->no_checkout) {
flags += " --no-checkout ";
}

if (!this->branch.empty()) {
flags += " --branch " + this->branch;
}
Expand Down Expand Up @@ -146,6 +150,11 @@ namespace Frate::System {

this->raw_result = out.std_out;
this->raw_error = out.std_err;

if (!this->raw_error.empty()) {
throw GitException(this->raw_error);
}

std::vector<GitRef> refs = parse_refs(out.std_out);
/*
* sorts refs into their respective vectors
Expand All @@ -168,9 +177,6 @@ namespace Frate::System {
}
}

if (!this->raw_error.empty()) {
throw GitException(this->raw_error);
}
return *this;
}

Expand Down Expand Up @@ -345,6 +351,11 @@ namespace Frate::System {
return *this;
}

GitProvider &GitProvider::setNoCheckout(bool no_checkout) {
this->no_checkout = no_checkout;
return *this;
}

GitProvider &GitProvider::setWorkingDir(std::filesystem::path path) {
if (!std::filesystem::exists(path)) {
throw GitException("Path does not exist");
Expand Down

0 comments on commit beab83e

Please sign in to comment.