From ae0048ef3d03c1511f2e12e0fdb5ae8d28061dab Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 2 Apr 2023 12:46:44 +0200 Subject: Add command to clone the source repository --- src/command.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/command.cpp') diff --git a/src/command.cpp b/src/command.cpp index 4066c23..0fa6bf1 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1,5 +1,6 @@ #include "command.h" #include +#include "config.h" namespace katja { @@ -17,7 +18,33 @@ namespace katja void help::execute() const { std::cout << "Usage:\n" - "\tkatja {info|help} [OPTIONS]\n\n"; + "\tkatja {list|update|help} [OPTIONS]\n\n"; + } + + update::update() + : git_binary(boost::process::search_path("git")) + { + } + + void update::execute() const + { + std::filesystem::path workdir{ WORKDIR }; + std::filesystem::path repository = workdir / "sbo/repository"; + std::filesystem::file_status repository_status = std::filesystem::status(repository); + + if (std::filesystem::exists(repository_status) + && !std::filesystem::is_directory(repository_status)) + { + throw std::runtime_error("The working directory path \"" + + repository.string() + "\" exists, but it isn't a directory."); + } + else if (!std::filesystem::exists(repository_status)) + { + git("clone", std::filesystem::path(), + "git://git.slackbuilds.org/slackbuilds.git", repository.native()); + } + git("remote", repository.native(), "update", "--prune"); + git("reset", repository.native(), "--hard", "origin/master"); } command_exception::command_exception(const command_exception_t exception_type, @@ -65,6 +92,10 @@ namespace katja { return std::make_unique(); } + else if (strcmp(argv[1], "update") == 0) + { + return std::make_unique(); + } else if (strcmp(argv[1], "help") == 0) { return std::make_unique(); -- cgit v1.2.3